public ActionResult Edit(ProductPackagingDTO model)
        {
            try
            {
                var entity = _dtoToEntityMapping.Map(model);

                var vri = _productPackagingRepository.Validate(entity);
                if (vri.IsValid)
                {
                    _productPackagingRepository.Save(entity, true);
                }
                else
                {
                    int i = 1;
                    foreach (ValidationResult error in vri.Results)
                    {
                        TempData["msg"] = string.Format("\n({0}).{1}", i, error.ErrorMessage);
                        ModelState.AddModelError("", error.ErrorMessage);
                        i++;
                    }
                   
                    return View(model);
                }
                TempData["msg"] = "Product Packaging added successfully";
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
              
                return View(model);
            }
        }
        private async Task<ImportValidationResultInfo> MapAndValidate(ProductPackagingDTO dto, int index)
        {
            return await Task.Run(() =>
            {
                if (dto == null) return null;
                var entity = _mappingService.Map(dto);
                var exist = _ctx.tblProductPackaging.FirstOrDefault(p => p.Name.ToLower() == dto.Name.ToLower()||
                    p.code !=null&& p.code.ToLower()==dto.Code.ToLower());

                entity.Id = exist == null ? Guid.NewGuid() : exist.Id;

                var res = _repository.Validate(entity);
                var vResult = new ImportValidationResultInfo()
                {
                    Results = res.Results,
                    Description =
                        string.Format("Row-{0} name or code=>{1}", index,
                                      entity.Name ?? entity.Code),
                    Entity = entity
                };
                return vResult;

            });


        }
 private ProductPackagingDTO Map(tblProductPackaging tbl)
 {
     var dto = new ProductPackagingDTO
                   {
                       MasterId = tbl.Id,
                       DateCreated = tbl.IM_DateCreated,
                       DateLastUpdated = tbl.IM_DateLastUpdated,
                       StatusId = tbl.IM_Status,
                       Name = tbl.Name,
                       Code = tbl.code,
                       Description = tbl.description,
                       ContainmentMasterId = tbl.Containment ?? Guid.Empty,
                       ReturnableProductMasterId = tbl.ReturnableProduct ?? Guid.Empty
                   };
     return dto;
 }
        public ActionResult Edit(Guid? id)
        {
            var model = new ProductPackagingDTO();
            if (id.HasValue)
            {
                var p = _productPackagingRepository.GetById(id.Value);
                if (p != null)
                    model = _masterDataToDtoMapping.Map(p);
                model.MasterId = id.Value;

            }

            if (model.MasterId == Guid.Empty)
                model.MasterId = Guid.NewGuid();
            return View(model);
        }
Пример #5
0
 public ProductPackaging Map(ProductPackagingDTO dto)
 {
     if (dto == null) return null;
     var productPackaging = Mapper.Map<ProductPackagingDTO, ProductPackaging>(dto);
     productPackaging.Containment = _containmentRepository.GetById(dto.ContainmentMasterId);
     return productPackaging;
 }