Triggering the Communication Service
Argument
Type/Return Type
Description/Typical Value
// Copyright (c) ComUnity 2017
using ComUnity.DataServices;
using ComUnity.DataServices.DomainUtility.Exceptions;
using ComUnity.DataServices.DomainUtility.Security;
using ComUnity.DataServices.ServiceUtility;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Services;
using System.Data.Services.Providers;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
namespace FaultComms.Models
{
public partial class Fault
{
// START auto-generated - CTOR
public Fault() : base()
{
// END auto-generated, add custom code below this line
}
// START auto-generated - OnAdd
public override void OnAdd(FaultCommsContext context)
{
base.OnAdd(context);
FaultStatus status = context.Set<FaultStatus>().FirstOrDefault();
Status = status ?? throw new GeneralException(400, "General", "No status defined in database!");
context.SaveChanges();
DateTime dt = DateTime.Now;
string refString = dt.ToShortDateString() + "-" + FaultId;
ReferenceNumber = refString;
var toAddress = Config.FaultEmail();
var an = Config.AppName();
var cs = Config.ComsService();
if (toAddress != null && an != null && cs != null)
{
var payload = ComsServices.JsonSerialize(this);
ComsServices.TriggerEvent(an, "OnAddFault", payload, cs, Config.ComsServiceUsername(), Config.ComsServicePassword());
}
// END auto-generated, add custom code below this line
}
// START auto-generated - OnChange
public override void OnChange(FaultCommsContext context)
{
base.OnChange(context);
int prevStatus = context.Entry(this).OriginalValues.GetValue<int>("StatusFaultStatusId");
if (StatusFaultStatusId != prevStatus)
{
var an = Config.AppName();
var cs = Config.ComsService();
if (an != null && cs != null)
{
var payload = ComsServices.JsonSerialize(this);
// ComsServices.TriggerEvent() invocation
ComsServices.TriggerEvent(an, "OnChangeFault", payload, cs, Config.ComsServiceUsername(), Config.ComsServicePassword());
}
}
// END auto-generated, add custom code below this line
}
// START auto-generated - OnDelete
public override void OnDelete(FaultCommsContext context)
{
base.OnDelete(context);
// END auto-generated, add custom code below this line
}
// START auto-generated - Filter start
public static Expression<Func<Fault,bool>> Filter(FaultCommsContext context)
{
Expression<Func<Fault, bool>> filter = o => true;
// END auto-generated, add custom code below this line
// START auto-generated - Filter end
return filter;
}
// END auto-generated, add custom code below this line
// START auto-generated - OnSeed
public static void OnSeed(FaultCommsContext context)
{
// END auto-generated, add custom code below this line
}
}
}