Esempio n. 1
0
 public void SubmitForm(Exception ex)
 {
     try
     {
         ErrorLogEntity errorLogEntity = new ErrorLogEntity();
         errorLogEntity.Date       = DateTime.Now;
         errorLogEntity.Message    = ex.Message;
         errorLogEntity.Source     = ex.Source;
         errorLogEntity.TargetSite = ex.TargetSite.Name;
         errorLogEntity.StackTrace = ex.StackTrace;
         service.Insert(errorLogEntity);
     }
     catch (Exception ex1)
     {
         throw;
     }
 }
        public bool Save(DeviceInformations deviceInformations)
        {
            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    var model = new DeviceInformations
                    {
                        DeviceGuid       = Guid.NewGuid().ToString(),
                        DeviceLocationId = deviceInformations.DeviceLocationId,
                        DeviceName       = deviceInformations.DeviceName,
                        DeivceToken      = Guid.NewGuid().ToString().ToUpper(), //Regex.Replace(Guid.NewGuid().ToString(), "[^0-9a-zA-Z]", string.Empty).ToUpper(),
                        DeviceCode       = deviceInformations.DeviceCode,
                        CreatedOn        = DateTime.Now,
                        UpdatedOn        = DateTime.Now
                    };

                    context.Add(model);
                    context.SaveChanges();

                    //update device serial number
                    this.deviceSerailNumberRepository.SetDeviceSerialNumber(model.DeviceCode);

                    //if all success - commit first step (second step was success completed)
                    transaction.Commit();

                    return(true);
                }
                catch (Exception Ex)
                {
                    errorLogRepository.Insert(new ErrorLog
                    {
                        EvenName     = "Save Device Informations Failed",
                        ErrorDetails = Ex.GetBaseException().Message
                    });
                    //if we have error - rollback first step (second step not be able accepted)
                    transaction.Rollback();
                    throw;
                }
            }
        }