public ActionResult Edit(ProviderEditModel model)
        {
            if (!ModelState.IsValid)
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage + x.Exception));
                this.AddNotification(messages, NotificationType.ERROR);
                return(View(model));
            }

            try
            {
                //Begin db transaction
                var shopInfo = ExtractEditFormData(model);

                var isSuccess = _mainStore.Update(shopInfo);
                if (isSuccess)
                {
                    //Clear cache
                    CachingHelpers.ClearProviderCache();

                    this.AddNotification(NotifSettings.Success_Updated, NotificationType.SUCCESS);
                }
            }
            catch (Exception ex)
            {
                this.AddNotification(NotifSettings.Error_SystemBusy, NotificationType.ERROR);

                logger.Error("Failed for Edit Provider POST request: " + ex.ToString());
            }

            return(RedirectToAction("Edit/" + model.Id));
        }
        public async Task <IActionResult> Get(Guid?id = null)
        {
            ProviderEditModel providerEditModel;

            if (id == null)
            {
                providerEditModel = new ProviderEditModel();

                return(Ok(providerEditModel));
            }

            var provider = await scvContext.Providers
                           .Where(p => p.Id == id)
                           .Cacheable()
                           .SingleOrDefaultAsync();

            if (provider == null)
            {
                return(NotFound());
            }

            providerEditModel = new ProviderEditModel
            {
                Id         = provider.Id,
                Name       = provider.Name,
                BaseApiUrl = provider.BaseApiUrl
            };

            return(Ok(providerEditModel));
        }
        private ProviderEditModel RenderEditModel(IdentityProvider identity)
        {
            var editModel = new ProviderEditModel();

            editModel.Id = identity.Id;

            editModel.Name    = identity.Name;
            editModel.Code    = identity.Code;
            editModel.Phone   = identity.Phone;
            editModel.Email   = identity.Email;
            editModel.Address = identity.Address;
            editModel.Status  = identity.Status;
            editModel.Email   = identity.Email;

            return(editModel);
        }
        private IdentityProvider ExtractEditFormData(ProviderEditModel formData)
        {
            var myIdetity = new IdentityProvider();

            myIdetity.Id = formData.Id;

            myIdetity.Name    = formData.Name;
            myIdetity.Code    = formData.Code;
            myIdetity.Phone   = formData.Phone;
            myIdetity.Email   = formData.Email;
            myIdetity.Address = formData.Address;
            myIdetity.Status  = formData.Status;
            myIdetity.Email   = formData.Email;

            return(myIdetity);
        }
Exemple #5
0
        public async Task <IActionResult> Edit(Guid id, ProviderEditModel model)
        {
            var provider = await _providerRepository.GetByIdAsync(id);

            if (provider == null)
            {
                return(RedirectToAction("Index"));
            }

            model.ToProvider(provider);
            await _providerRepository.ReplaceAsync(provider);

            await _applicationCacheService.UpsertProviderAbilityAsync(provider);

            return(RedirectToAction("Edit", new { id }));
        }
        public async Task <IActionResult> Put(
            [FromRoute] Guid id,
            [
                FromBody,
                Bind
                (
                    nameof(ProviderEditModel.Id),
                    nameof(ProviderEditModel.Name),
                    nameof(ProviderEditModel.BaseApiUrl)
                )
            ] ProviderEditModel providerEditModel)
        {
            if (!ModelState.IsValid || id != providerEditModel.Id)
            {
                return(BadRequest(ModelState));
            }

            var provider = await scvContext.Providers
                           .Where(p => p.Id == id)
                           .Cacheable()
                           .SingleOrDefaultAsync();

            if (provider == null)
            {
                return(NotFound());
            }

            provider.Name       = providerEditModel.Name;
            provider.BaseApiUrl = providerEditModel.BaseApiUrl;

            scvContext.Providers.Update(provider);

            await scvContext.SaveChangesAsync();

            return(Ok(providerEditModel));
        }