コード例 #1
0
        public async Task <ActionResult> Edit(Guid id, EditPackagingViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            if (!id.Equals(request.Id))
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var packagingUpdateRequest = new UpdatePackagingRequest {
                    Id = request.Id, Name = request.Name, Description = request.Description
                };
                var result = await _packagingService.Update(id, packagingUpdateRequest);

                if (!result.Success)
                {
                    Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }

                Alert($"Packaging Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
コード例 #2
0
        // GET: Packagings/Edit/5
        public async Task <ActionResult> Edit(Guid id)
        {
            var packaging = new EditPackagingViewModel();

            try
            {
                var result = await _packagingService.FindById(id);

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View(packaging));
                }
                packaging.Id          = result.Data.Id;
                packaging.Name        = result.Data.Name;
                packaging.Description = result.Data.Description;
                return(View(packaging));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View(packaging));
            }
        }