Example #1
0
        public TEntity Create(TEntity entity)
        {
            Context.Set <TEntity>().Add(entity);
            Context.SaveChanges();

            return(entity);
        }
Example #2
0
        public TEntity Create <TEntity>(TEntity ent) where TEntity : class
        {
            context.Set <TEntity>().Add(ent);
            context.SaveChanges();

            return(ent);
        }
Example #3
0
        public async void SaveIOLog(string action, string actionDescription, Guid id)
        {
            bool ioLogSwitch = Convert.ToBoolean(AppSettings.Configuration["EnableInspectionOrderLogs"]);

            if (ioLogSwitch)
            {
                var inspectionOrder = await this.RetrieveIO(id);

                this.UpdateInspectionOrder(inspectionOrder);

                string ioString = Utils.SerializeObjectToJson(inspectionOrder);

                var currentUser = this.context.GetCurrentUser();
                var user        = _accountRepository.Retrieve(currentUser);

                InspectionOrderLogs inspectionOrderLogs = new InspectionOrderLogs
                {
                    InspectionOrderJsonData = ioString,
                    Action            = action,
                    ActionDescription = actionDescription,
                    DateCreated       = DateTime.Now,
                    InspectionOrderId = id,
                    CreatedById       = user.Id
                };

                context.Set <InspectionOrderLogs>().Add(inspectionOrderLogs);

                context.SaveChanges();
            }
        }
Example #4
0
        public void CreateOrUpdate(InspectionOrderNote ent)
        {
            string action;
            string actionDescription;

            var dbSet      = context.Set <InspectionOrderNote>();
            var existingIO = dbSet
                             .SingleOrDefault(a => a.Id == ent.Id);

            if (existingIO == null)
            {
                dbSet.Add(ent);
                action            = InspectionOrderLogActionsConstants.CreatedNote;
                actionDescription = InspectionOrderLogActionsConstants.CreatedNote;
            }
            else
            {
                context.Entry(existingIO).CurrentValues.SetValues(ent);
                action            = InspectionOrderLogActionsConstants.UpdatedNote;
                actionDescription = InspectionOrderLogActionsConstants.UpdatedNote;
            }
            context.SaveChanges();

            _inspectionOrderLogRepository.SaveIOLog(action, actionDescription, ent.InspectionOrderId);
        }
Example #5
0
        public Image InsertOrUpdateWildfireAssessmentChildMitigationRecommendation(InspectionOrder ioFromClient)
        {
            var parentMitigationRecommendation = ioFromClient.WildfireAssessment.Mitigation.Recommendations.First();

            var existingIoWaParentMitigationRecommendation = Context.Set <InspectionOrderWildfireAssessmentMitigationRecommendations>()
                                                             .Include(x => x.ChildMitigation)
                                                             .ThenInclude(x => x.Image)
                                                             .SingleOrDefault(x => x.Id.Equals(parentMitigationRecommendation.Id));

            if (existingIoWaParentMitigationRecommendation == null)
            {
                throw new Exception("Inspection Order not found.");
            }

            var mrFromClient = parentMitigationRecommendation.ChildMitigation.First();

            mrFromClient.IoWaParentMitigationRecommendationsId = parentMitigationRecommendation.Id;

            var childMitigationDbSet = context.Set <InspectionOrderWildfireAssessmentChildMitigationRecommendations>();

            var imageFromClient = mrFromClient.Image;

            var isAdd = (imageFromClient.Id == Guid.Empty);
            var newId = Guid.NewGuid();

            if (isAdd)
            {
                if (mrFromClient.Image.File != null)
                {
                    imageFromClient.Id = newId;
                    _imageService.UpdateImageFile(imageFromClient, newId);

                    mrFromClient.Image = imageFromClient;
                }

                childMitigationDbSet.Add(mrFromClient);

                context.SaveChanges();

                return(mrFromClient.Image);
            }
            else
            {
                var existingPm = childMitigationDbSet.SingleOrDefault(
                    w => w.IoWaParentMitigationRecommendationsId == mrFromClient.IoWaParentMitigationRecommendationsId &&
                    w.ImageId == imageFromClient.Id);

                if (existingPm == null)
                {
                    throw new Exception("Image not found.");
                }

                context.Entry(existingPm).CurrentValues.SetValues(mrFromClient);

                // this means that the image file from the client has changed
                if (imageFromClient.File != null)
                {
                    _imageService.UpdateImageFile(imageFromClient, newId);

                    var existingImage = _imageRepository.Retrieve(existingPm.ImageId);

                    context.Entry(existingImage).CurrentValues.SetValues(imageFromClient);

                    try
                    {
                        context.SaveChanges();

                        _imageService.DeleteImageFileInDisk(existingPm.Image.FilePath);
                        _imageService.DeleteImageFileInDisk(existingPm.Image.ThumbnailPath);

                        return(existingPm.Image);
                    }
                    catch (Exception e)
                    {
                    }
                }
                else
                {
                    context.SaveChanges();
                }


                return(imageFromClient);
            }
        }
Example #6
0
 public void CreateUser(ApplicationUser user)
 {
     context.Set <ApplicationUser>().Add(user);
     context.SaveChanges();
 }
        public Image InsertOrUpdateWildfireAssessmentMitigationRequirement(InspectionOrder ioFromClient)
        {
            var existingIo = Context.Set <InspectionOrder>()
                             .Include(x => x.WildfireAssessment)
                             .ThenInclude(x => x.Mitigation)
                             .ThenInclude(x => x.Requirements)
                             .SingleOrDefault(x => x.Id.Equals(ioFromClient.Id));

            if (existingIo == null)
            {
                throw new Exception("Inspection Order not found.");
            }

            var wildfireAssessment = existingIo.WildfireAssessment;

            if (wildfireAssessment == null)
            {
                wildfireAssessment = new InspectionOrderWildfireAssessment {
                    Id = ioFromClient.Id
                };
                context.Entry(wildfireAssessment).State = EntityState.Added;
            }

            var mitigation = wildfireAssessment.Mitigation;

            if (mitigation == null)
            {
                mitigation = new InspectionOrderWildfireAssessmentMitigation {
                    Id = ioFromClient.Id
                };
                context.Entry(mitigation).State = EntityState.Added;
            }

            if (mitigation.Requirements == null)
            {
                mitigation.Requirements = new List <InspectionOrderWildfireAssessmentMitigationRequirements>();
            }

            var pmFromClient = ioFromClient.WildfireAssessment.Mitigation.Requirements.First();

            pmFromClient.InspectionOrderWildfireAssessmentMitigationId = mitigation.Id;

            var requirementsDbSet = context.Set <InspectionOrderWildfireAssessmentMitigationRequirements>();

            var imageFromClient = pmFromClient.Image;

            var isAdd = (imageFromClient.Id == Guid.Empty);
            var newId = Guid.NewGuid();

            if (isAdd)
            {
                imageFromClient.Id = newId;
                _imageService.UpdateImageFile(imageFromClient, newId);

                pmFromClient.Image = imageFromClient;
                requirementsDbSet.Add(pmFromClient);

                context.SaveChanges();

                return(pmFromClient.Image);
            }
            else // update
            {
                var existingPm = requirementsDbSet.SingleOrDefault(
                    w => w.InspectionOrderWildfireAssessmentMitigationId == pmFromClient.InspectionOrderWildfireAssessmentMitigationId &&
                    w.ImageId == imageFromClient.Id);

                if (existingPm == null)
                {
                    throw new Exception("Image not found.");
                }

                context.Entry(existingPm).CurrentValues.SetValues(pmFromClient);

                // this means that the image file from the client has changed
                if (imageFromClient.File != null)
                {
                    _imageService.UpdateImageFile(imageFromClient, newId);

                    var existingImage = _imageRepository.Retrieve(existingPm.ImageId);

                    context.Entry(existingImage).CurrentValues.SetValues(imageFromClient);

                    try
                    {
                        context.SaveChanges();

                        _imageService.DeleteImageFileInDisk(existingPm.Image.FilePath);
                        _imageService.DeleteImageFileInDisk(existingPm.Image.ThumbnailPath);

                        return(existingPm.Image);
                    }
                    catch (Exception e)
                    {
                    }
                }
                else
                {
                    context.SaveChanges();
                }


                return(imageFromClient);
            }
        }
Example #8
0
        public void AddRoleToUser(ApplicationUserRole userRole)
        {
            context.Set <ApplicationUserRole>().Add(userRole);

            context.SaveChanges();
        }