public async Task <bool> SendEmailToInspector(InspectionOrder inspectionOrder, string webHost)
        {
            try
            {
                var selectedInspector = await _userManager.FindByIdAsync(inspectionOrder.InspectorId.ToString());

                var inspectorFullName = selectedInspector.FirstName + " " + selectedInspector.LastName;

                var selectedManager = await _userManager.FindByIdAsync(inspectionOrder.AssignedById.ToString());

                var managerfullName = selectedManager.FirstName + " " + selectedManager.LastName;

                var emailBody = new StringBuilder();
                emailBody.AppendLine($"<p>Dear {inspectorFullName} ,</p>");
                emailBody.AppendLine($"<p>The Inspection Order with Policy: {inspectionOrder.Policy.PolicyNumber}</p>");
                emailBody.AppendLine($"<p>has been rejected by {managerfullName}</p>");
                emailBody.AppendLine("<p>please see inspection order notes for further explanation</p>");

                _accountcontrollerService.SendEmail("Inspection Report Review", selectedInspector.Email,
                                                    emailBody.ToString());
            }
            catch (Exception e)
            {
                throw new Exception("Error on sending email to Manager.");
            }

            return(true);
        }
        public async Task <bool> SendEmailToInspectionUWA(InspectionOrder inspectionOrder, string webHost)
        {
            try
            {
                var selectedInspector = await _userManager.FindByIdAsync(inspectionOrder.InspectorId.ToString());

                var inspectorFullName = selectedInspector.FirstName + " " + selectedInspector.LastName;

                var selectedUnderWriter = await _userManager.FindByIdAsync(inspectionOrder.CreatedById.ToString());

                var underWriterFullName = selectedUnderWriter.FirstName + " " + selectedUnderWriter.LastName;

                var emailBody = new StringBuilder();
                emailBody.AppendLine($"<p>Dear {inspectorFullName} ,</p>");
                emailBody.AppendLine($"<p>The Inspection Order with Policy: {inspectionOrder.Policy.PolicyNumber}</p>");
                emailBody.AppendLine($"<p>has been accepted by {underWriterFullName}</p>");

                _accountcontrollerService.SendEmail("Inspection Report Review", selectedInspector.Email,
                                                    emailBody.ToString());
            }
            catch (Exception e)
            {
                throw new Exception("Error on sending email to Manager.");
            }

            return(true);
        }
Esempio n. 3
0
        public async Task <IActionResult> CreateNonWildfireAssessmentChildMitigationRecommendation([FromBody] dynamic data)
        {
            try
            {
                if (data == null)
                {
                    return(BadRequest());
                }

                string          Name = data.property.nonWildfireAssessment.mitigation.recommendations[0].childMitigation[0].userId;
                ApplicationUser user = await _userManager.FindByNameAsync(Name);

                if (user == null)
                {
                    data.property.nonWildfireAssessment.mitigation.recommendations[0].childMitigation[0].userId = null;
                }
                else
                {
                    data.property.nonWildfireAssessment.mitigation.recommendations[0].childMitigation[0].userId = user.Id;
                }

                var image = data.property.nonWildfireAssessment.mitigation.recommendations[0].childMitigation[0].image;

                if (image.file != null)
                {
                    string       strPhoto = image.file;
                    const string dataUri  = "data:image/jpeg;base64,";
                    if (strPhoto.StartsWith(dataUri))
                    {
                        strPhoto   = strPhoto.Substring(dataUri.Length).TrimStart();
                        image.file = Convert.FromBase64String(strPhoto);
                    }
                    else
                    {
                        // this means that this is update
                        // and image file is not changed
                        image.file     = null;
                        image.filePath = strPhoto;
                    }
                }

                InspectionOrder io = Utils.ConvertTo <InspectionOrder>(data);
                if (io == null)
                {
                    return(BadRequest());
                }

                //var existingImage =
                _inspectionOrderPropertyNonWildfireAssessmentChildMitigationRecommendationsRepository.InsertOrUpdateNonWildfireAssessmentChildMitigationRecommendation(io);

                //existingImage.File = null;
                //existingImage.Thumbnail = null;

                return(Ok());                // Ok(existingImage);
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
Esempio n. 4
0
        public IActionResult CreateInspectionOrder([FromBody] dynamic data)
        {
            try
            {
                if (data == null)
                {
                    return(BadRequest());
                }

                InspectionOrder inspectionOrder = Utils.ConvertTo <InspectionOrder>(data);
                if (inspectionOrder == null)
                {
                    return(BadRequest());
                }

                // Set status to pending assignment
                //inspectionOrder.Policy.InspectionStatusId = InspectionStatusConstants.PendingAssignment;

                if (string.IsNullOrEmpty(inspectionOrder.InspectorId.ToString()))
                {
                    inspectionOrder.AssignedDate = null;
                }
                else
                {
                    inspectionOrder.AssignedDate = DateTime.Now.Date;
                }

                inspectionOrder.CreatedDate = DateTime.Now.Date;

                var inspectionDate = (DateTime?)data.inspectionDate;

                if (inspectionDate == null)
                {
                    inspectionOrder.InspectionDate = null;
                }
                else
                {
                    if (inspectionOrder.Policy.InspectionStatusId.Equals("S"))
                    {
                        inspectionOrder.InspectionDate = inspectionDate;
                    }
                    else
                    {
                        inspectionOrder.InspectionDate = null;
                    }
                }

                var userId = _rivingtonContext.GetCurrentUser();
                inspectionOrder.CreatedById = userId;

                _inspectionOrderRepository.InsertOrUpdateIO(inspectionOrder);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> UpdateInspectionOrder([FromBody] dynamic data)
        {
            try
            {
                var updatedStatus = "";
                if (data == null)
                {
                    return(BadRequest());
                }
                InspectionOrder inspectionOrder = Utils.ConvertTo <InspectionOrder>(data);

                var updatedInspectionOrder = _inspectionOrderRepository.Retrieve(inspectionOrder.Id);
                if (updatedInspectionOrder == null)
                {
                    return(NotFound());
                }

                var headers       = this.HttpContext.Request.Headers;
                var contentSource = headers["Content-Source"].ToString();
                if (contentSource == "mobile/ios")
                {
                    var isSync = headers["Custom-IG-Is-Sync"].ToString().ToBoolean();
                    if (isSync && !updatedInspectionOrder.IsLocked)
                    {
                        return(BadRequest(new
                        {
                            status = "IOUnlocked",
                            message = "IO is already unlocked."
                        }));
                    }
                }

                if (updatedInspectionOrder.IsLocked &&
                    !updatedInspectionOrder.IsLockedById.Equals(_rivingtonContext.GetCurrentUser())
                    )
                {
                    return(BadRequest(new
                    {
                        status = "InvalidIOLockedBy",
                        message = "IO is locked to other user."
                    }));
                }

                var assignedById = _rivingtonContext.GetCurrentUser();
                inspectionOrder = _inspectionOrderService.ProcessIO(inspectionOrder, assignedById);

                _inspectionOrderRepository.InsertOrUpdateIO(inspectionOrder);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
Esempio n. 6
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();
        }
        public InspectionOrder ProcessIO(InspectionOrder inspectionOrder, Guid assignedById)
        {
            // From Pending Assignment to Ready To Schedule
            //if (inspectionOrder.InspectorId != null &&
            //    inspectionOrder.Policy.InspectionStatusId == InspectionStatusConstants.PendingAssignment)
            //{
            //    inspectionOrder.Policy.InspectionStatusId = InspectionStatusConstants.ReadyToSchedule;
            //}

            // From Ready To Schedule to Scheduled
            //if (inspectionOrder.Policy.InspectionStatusId == InspectionStatusConstants.ReadyToSchedule &&
            //    inspectionOrder.InspectionDate != null)
            //{
            //    inspectionOrder.Policy.InspectionStatusId = InspectionStatusConstants.Scheduled;
            //}

            switch (inspectionOrder.Policy.InspectionStatusId)
            {
            case InspectionStatusConstants.PendingAssignment:
                inspectionOrder.CreatedDate = DateTime.Now.Date;
                break;

            case InspectionStatusConstants.ReadyToSchedule:
                inspectionOrder.AssignedDate = DateTime.Now.Date;
                inspectionOrder.AssignedById = assignedById;
                break;

            case InspectionStatusConstants.Scheduled:
                if (inspectionOrder.AssignedById == null)
                {
                    inspectionOrder.AssignedDate = DateTime.Now.Date;
                    inspectionOrder.AssignedById = assignedById;
                }
                this.SendInsuredEmailOnScheduled(inspectionOrder, Domain.CustomCodes.AppSettings.WebHost);
                break;

            default:
                break;
            }

            if (inspectionOrder.Policy.MitigationStatusId == MitigationStatusConstants.OutstandingItems ||
                inspectionOrder.Policy.MitigationStatusId == MitigationStatusConstants.Completed ||
                inspectionOrder.Policy.MitigationStatusId == MitigationStatusConstants.NoneRequired)
            {
                _inspectionOrderRepository.SendEmailToInsured(
                    Domain.CustomCodes.AppSettings.WebHost,
                    Domain.CustomCodes.AppSettings.EmailSender,
                    inspectionOrder);
            }

            return(inspectionOrder);
        }
Esempio n. 8
0
        public async Task <IActionResult> Put([FromBody] InspectionOrder inspectionOrder)
        {
            try
            {
                _inspectionOrderRepository.UpdateIOChecklist(inspectionOrder);
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }

            return(Ok());
        }
        public async Task <IActionResult> Post([FromForm] InspectionorderViewModel model)
        {
            var date      = DateTime.Now;
            var filesname = "null";
            var random    = RandomString(15);

            //ตรวจสอบว่ามี Folder Upload ใน wwwroot มั้ย
            if (!Directory.Exists(_environment.WebRootPath + "/assets" + "//InspectionorderFile//"))
            {
                Directory.CreateDirectory(_environment.WebRootPath + "/assets" + "//InspectionorderFile//"); //สร้าง Folder Upload ใน wwwroot
            }

            ////var BaseUrl = url.ActionContext.HttpContext.Request.Scheme;
            //// path ที่เก็บไฟล์
            var filePath = _environment.WebRootPath + "/assets" + "//InspectionorderFile//";

            if (model.files != null)
            {
                foreach (var formFile in model.files.Select((value, index) => new { Value = value, Index = index }))
                ////foreach (var formFile in data.files)
                {
                    string filePath2 = formFile.Value.FileName;
                    string filename  = Path.GetFileName(filePath2);
                    string ext       = Path.GetExtension(filename);

                    if (formFile.Value.Length > 0)
                    {
                        // using (var stream = System.IO.File.Create(filePath + formFile.Value.FileName))
                        using (var stream = System.IO.File.Create(filePath + random + ext))
                        {
                            await formFile.Value.CopyToAsync(stream);

                            filesname = random + ext;
                        }
                    }
                }
            }
            var inspectionorderdata = new InspectionOrder
            {
                Name     = model.Name,
                Year     = model.Year,
                Order    = model.Order,
                File     = filesname,
                CreateBy = model.CreateBy,
            };

            _context.InspectionOrders.Add(inspectionorderdata);
            _context.SaveChanges();
            return(Ok(new { Id = inspectionorderdata.Id, title = model.Name }));
        }
Esempio n. 10
0
        public InspectionOrder Post(string name)
        {
            var date = DateTime.Now;

            var inspectionorderdata = new InspectionOrder
            {
                Name      = name,
                CreatedAt = date
            };

            _context.InspectionOrders.Add(inspectionorderdata);
            _context.SaveChanges();

            return(inspectionorderdata);
        }
        public InspectionOrder Save(Guid id, InspectionOrder inspectionOrder)
        {
            InspectionOrder result  = null;
            var             foundid = _inspectionOrderRepository.Retrieve(id);

            if (foundid == null)
            {
                inspectionOrder.CreatedDate  = DateTime.Now;
                inspectionOrder.AssignedDate = DateTime.Now;
                result = _inspectionOrderRepository.Create(inspectionOrder);
            }
            else
            {
                result = _inspectionOrderRepository.Update(id, inspectionOrder);
            }
            return(result);
        }
Esempio n. 12
0
        public IActionResult CreateNonWildfireAssessmentMitigationRecommendation([FromBody] dynamic data)
        {
            try
            {
                if (data == null)
                {
                    return(BadRequest());
                }

                var          image    = data.property.nonWildfireAssessment.mitigation.recommendations[0].image;
                string       strPhoto = image.file;
                const string dataUri  = "data:image/jpeg;base64,";
                if (strPhoto.StartsWith(dataUri))
                {
                    strPhoto   = strPhoto.Substring(dataUri.Length).TrimStart();
                    image.file = Convert.FromBase64String(strPhoto);
                }
                else
                {
                    // this means that this is update
                    // and image file is not changed
                    image.file     = null;
                    image.filePath = strPhoto;
                }

                InspectionOrder io = Utils.ConvertTo <InspectionOrder>(data);
                if (io == null)
                {
                    return(BadRequest());
                }

                //var existingImage =
                _inspectionOrderMitigationRepository.InsertOrUpdateNonWildfireAssessmentMitigationRecommendation(io);

                //existingImage.File = null;
                //existingImage.Thumbnail = null;

                return(Ok());                // Ok(existingImage);
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
Esempio n. 13
0
        public IActionResult UploadInspectionOrderPropertyPhotos([FromBody] dynamic data)
        {
            try
            {
                if (data == null)
                {
                    return(BadRequest());
                }

                var          image    = data.propertyPhoto.photos[0].image;
                string       strPhoto = image.file;
                const string dataUri  = "data:image/jpeg;base64,";
                if (strPhoto.StartsWith(dataUri))
                {
                    strPhoto   = strPhoto.Substring(dataUri.Length).TrimStart();
                    image.file = Convert.FromBase64String(strPhoto);
                }
                else
                {
                    // this means that this is update
                    // and image file is not changed
                    image.file     = null;
                    image.filePath = strPhoto;
                }

                InspectionOrder inspectionOrder = Utils.ConvertTo <InspectionOrder>(data);

                if (inspectionOrder == null)
                {
                    return(BadRequest());
                }

                var photo = _inspectionOrderRepository.InsertOrUpdateIoPropertyPhoto(inspectionOrder);
                photo.File      = null;
                photo.Thumbnail = null;

                return(Ok(photo));
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
        public bool SendInsuredEmailOnScheduled(InspectionOrder inspectionOrder, string webHost)
        {
            try
            {
                var selectedInspector = _accountRepository.Retrieve(Guid.Parse(inspectionOrder.InspectorId.ToString()));

                var emailBody = new StringBuilder();
                emailBody.AppendLine($"<p>Dear {inspectionOrder.Policy.InsuredFirstName},</p>");
                emailBody.AppendLine($"<p>Here is the schedule of the inspection of your property: <strong>{inspectionOrder.InspectionDate:MMMM dd, yyyy}</strong></p>");
                emailBody.AppendLine("<p>Your inspection order details:</p>");
                emailBody.AppendLine($"<p>Policy Number: {inspectionOrder.Policy.PolicyNumber}</p>");
                emailBody.AppendLine($"<p>Insured Name: {inspectionOrder.Policy.InsuredFirstName} {inspectionOrder.Policy.InsuredLastName}</p>");
                emailBody.AppendLine($"<p>Inception Date: {inspectionOrder.Policy.InceptionDate:MMMM dd, yyyy}</p>");
                emailBody.AppendLine($"<p><i><small>Please keep this details for future reference.</small></i></p>");
                emailBody.AppendLine("<p>Your property will be inspected by one of our expert. </p>");
                emailBody.AppendLine("<h4>Inspector Details:</h4>");

                var sPhotoPath =
                    selectedInspector.ProfilePhoto != null ?
                    selectedInspector.ProfilePhoto.FilePath :
                    "StaticFiles/default-user-profile-image.jpg";

                emailBody.AppendLine($"<img src='{webHost}/{sPhotoPath}' width ='150' height='150' >");

                emailBody.AppendLine($"<p><b>Inspector Name:</b> {selectedInspector.FirstName} {selectedInspector.LastName}</p>");

                emailBody.AppendLine($"<p><b>Inspector Email:</b> {selectedInspector.Email}</p>");
                emailBody.AppendLine("<p>Sincerely,<br>Inspector Gadget</br></p> ");

                _accountcontrollerService.SendEmail("Inspection Schedule", inspectionOrder.Policy.InsuredEmail,
                                                    emailBody.ToString());
            }
            catch (Exception e)
            {
                throw new Exception("Error on sending email to Insured.");
            }

            return(true);
        }
        public async Task <bool> SendEmailToManager(InspectionOrder inspectionOrder, string webHost)
        {
            try
            {
                var selectedManager = await _userManager.FindByIdAsync(inspectionOrder.AssignedById.ToString());

                var managerfullName = selectedManager.FirstName + " " + selectedManager.LastName;

                var emailBody = new StringBuilder();
                emailBody.AppendLine($"<p>Dear {managerfullName} ,</p>");
                emailBody.AppendLine($"<p>The Inspection Order with Policy: {inspectionOrder.Policy.PolicyNumber}</p>");
                emailBody.AppendLine("<p>is now pending for your review</p>");

                _accountcontrollerService.SendEmail("Inspection Report Review", selectedManager.Email,
                                                    emailBody.ToString());
            }
            catch (Exception e)
            {
                throw new Exception("Error on sending email to Manager.");
            }

            return(true);
        }
        public ReportTitleViewModel ConvertToTitlePageProperties(InspectionOrder inspectionOrder)
        {
            ReportTitleViewModel reportTitleView = new ReportTitleViewModel {
            };

            if (inspectionOrder != null)
            {
                if (inspectionOrder.Policy == null)
                {
                    inspectionOrder.Policy = new Policy();
                }
                if (inspectionOrder.Inspector == null)
                {
                    inspectionOrder.Inspector = new ApplicationUser();
                }

                reportTitleView = new ReportTitleViewModel
                {
                    Id = inspectionOrder.Id,
                    InsuredFullname         = inspectionOrder.Policy.InsuredFirstName + ' ' + inspectionOrder.Policy.InsuredLastName,
                    InsuredAddress          = inspectionOrder.Policy.Address,
                    InsuredCityStateZipCode = inspectionOrder.Policy.InsuredCity + ' ' + inspectionOrder.Policy.InsuredState + ' ' + inspectionOrder.Policy.InsuredZipCode,
                    InspectorFullName       = inspectionOrder.Inspector.FirstName + ' ' + inspectionOrder.Inspector.LastName,
                    InspectorEmail          = inspectionOrder.Inspector.Email,
                    InspectorMobileNumber   = inspectionOrder.Inspector.MobileNumber,
                    AgentName        = inspectionOrder.Policy.AgentName,
                    AgencyName       = inspectionOrder.Policy.AgencyName,
                    AgentPhoneNumber = inspectionOrder.Policy.AgentPhoneNumber,
                    InspectionDate   = inspectionOrder.InspectionDate,
                    PolicyNumber     = inspectionOrder.Policy.PolicyNumber,
                    Photo            = inspectionOrder.PropertyPhoto?.Photos?.OrderBy(x => x.Image.CreatedAt).FirstOrDefault(x => x.PhotoTypeId == "RC")?.Image.FilePath
                };
            }

            return(reportTitleView);
        }
        public InspectionOrder ConvertToIO(PolicyXMLResponse policyXML)
        {
            InspectionOrder                newIO              = new InspectionOrder();
            InspectionOrderProperty        newProperty        = new InspectionOrderProperty();
            InspectionOrderPropertyGeneral newPropertyGeneral = new InspectionOrderPropertyGeneral();

            string currentCity  = _cityRepository.RetrieveByName(policyXML.Property.LegalAddress.City, policyXML.Property.LegalAddress.State).Name;
            string currentState = _stateRepository.Retrieve(policyXML.Property.LegalAddress.State).Name;

            string fullAddress = $"{policyXML.Property.LegalAddress.Street1} {currentCity} {currentState} {policyXML.Property.LegalAddress.ZipCode}";

            var insuredName = policyXML.Policy.InsuredName.Split(' ');
            var nameLength  = insuredName.Length;

            var firstName = "";

            for (int i = 0; i < nameLength - 1; i++)
            {
                firstName = firstName + " " + insuredName[i];
            }
            var lastName = insuredName[nameLength - 1];

            //Policy
            Policy newPolicy = new Policy
            {
                PolicyNumber               = policyXML.Policy.PolicyNumber,
                InsuredFirstName           = firstName,
                InsuredLastName            = lastName,
                CoverageA                  = policyXML.Policy.Coverage,
                InceptionDate              = DateTime.Parse(policyXML.Policy.EffectiveDate),
                InsuredState               = currentState,
                InsuredZipCode             = policyXML.Property.LegalAddress.ZipCode,
                InsuredCity                = currentCity,
                Address                    = fullAddress,
                InsuredEmail               = AppSettings.Configuration["InsuredEmail"],
                WildfireAssessmentRequired = false,
                AgencyName                 = policyXML.Agent.Name,
                AgencyPhoneNumber          = policyXML.Agent.Phone.PhoneNumber,
                PropertyValueId            = PropertyValue(policyXML.Policy.Coverage),
                InspectionStatusId         = "PA"
            };

            var completePolicy = _mapService.GetAddressGeocode(newPolicy);

            newPolicy = completePolicy;

            //Property
            newPropertyGeneral.StreetAddress1 = policyXML.Property.LegalAddress.Street1;
            newPropertyGeneral.StreetAddress2 = "";
            newPropertyGeneral.StateId        = policyXML.Property.LegalAddress.State;
            newPropertyGeneral.ZipCode        = policyXML.Property.LegalAddress.ZipCode;
            newPropertyGeneral.CityId         = _cityRepository.RetrieveByName(policyXML.Property.LegalAddress.City, policyXML.Property.LegalAddress.State).Id;

            //Inspection Order
            newIO.CreatedDate     = DateTime.Now.Date;
            newIO.LastUpdatedDate = DateTime.Now.Date;

            var userId = GetUser("underwriter_user");

            newIO.CreatedById = new Guid(userId.Result);

            newIO.Policy           = newPolicy;
            newIO.Property         = newProperty;
            newIO.Property.General = newPropertyGeneral;

            return(newIO);
        }
Esempio n. 18
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);
            }
        }