コード例 #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));
        }