Пример #1
0
        public async Task <ActionResult> EditPackagingType(Guid id, EditPackagingTypeViewModel 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 packagingTypeEditRequest = new UpdatePackagingTypeRequest {
                    Id = request.Id, Name = request.Name, Description = request.Description, PackagingId = request.PackagingId
                };
                var result = await _packagingTypeService.Update(id, packagingTypeEditRequest);

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

                Alert($"Packaging Type Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(PackagingTypes), new { id = request.PackagingId }));
            }
            catch
            {
                Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
Пример #2
0
        public async Task <ActionResult> EditPackagingType(Guid id)
        {
            var packagingType = new EditPackagingTypeViewModel();

            try
            {
                var result = await _packagingTypeService.FindByIdInclusive(id, x => x.Include(p => p.Packaging));

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