示例#1
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);
        }
示例#2
0
        public void UpdateInspectionOrder(InspectionOrder ent)
        {
            ent.LastUpdatedDate = DateTime.Now;

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

            context.Entry(existingIO).CurrentValues.SetValues(ent);

            context.SaveChanges();
        }
示例#3
0
        public void CreateOrUpdate <TEntity>(Enumeration ent) where TEntity : class
        {
            string action;
            string actionDescription;

            var dbSet = context.Set <Enumeration>();
            //var existingEnum;
            //var existingEnum = dbSet.SingleOrDefault(a => a.Id == ent.Id );

            object existingEnum = null;

            if (existingEnum == null)
            {
                dbSet.Add(ent);
            }
            else
            {
                context.Entry(existingEnum).CurrentValues.SetValues(ent);
            }
            context.SaveChanges();
        }
示例#4
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);
            }
        }
        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);
            }
        }