コード例 #1
0
        public IActionResult Put(Guid key, string values)
        {
            Partner partner = _partnerRepo.GetByUid(key);

            if (partner == null)
            {
                return(StatusCode(409, "Partner not found"));
            }

            if (!TryValidateModel(partner))
            {
                return(BadRequest(GetFullErrorMessage(ModelState)));
            }

            JsonConvert.PopulateObject(values, partner);

            // Updating partner
            _partnerRepo.Update(partner);

            // Updating services
            // In editing mode
            //      - services are [] => all services removed
            //      - services are null => no changes
            var partnerVM = new PartnerVM();

            JsonConvert.PopulateObject(values, partnerVM);

            if (partnerVM.Services != null)
            {
                _partnerRepo.UpdateServices(key, partnerVM.Services);
            }

            // Updating logo
            if (!String.IsNullOrEmpty(partner.Logo))
            {
                // If the logo's name is equal to partner's id, means that there is no new logo updated.
                //
                if (Path.GetFileNameWithoutExtension(partner.Logo) != partner.Id.ToString())
                {
                    this.CreateLogoFromTempFile(partner);
                }
            }

            return(_uow.Commit() ? Ok() : StatusCode(StatusCodes.Status500InternalServerError));
        }
コード例 #2
0
        public ActionResult Edit(PartnerVM partnerVM)
        {
            RolesRepository rolesRepository = new RolesRepository();

            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Update  Model from Form
            try
            {
                TryUpdateModel <Partner>(partnerVM.Partner, "Partner");
            }
            catch
            {
                string n = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        n += error.ErrorMessage;
                    }
                }
                ViewData["Message"] = "ValidationError : " + n;
                return(View("Error"));
            }

            try
            {
                partnerRepository.Update(partnerVM);
            }
            catch (SqlException ex)
            {
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }

            return(RedirectToAction("List"));
        }