Ejemplo n.º 1
0
        public ActionResult Edit(SupplierDTO model)
        {
            try
            {
                var entity = _dtoToEntityMapping.Map(model);

                var vri = _supplierRepository.Validate(entity);
                if (vri.IsValid)
                {
                    _supplierRepository.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"] = "Supplier added successfully";
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
               
                return View(model);
            }
        }
Ejemplo n.º 2
0
        private async Task<ImportValidationResultInfo> MapAndValidate(SupplierDTO dto, int index)
        {
            return await Task.Run(() =>
            {
                if (dto == null) return null;
                var entity = _mappingService.Map(dto);
                var exist = _ctx.tblSupplier.FirstOrDefault(p => p.Code.ToLower() == dto.Code.ToLower() || p.Name.ToLower() == dto.Name.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 SupplierDTO Map(tblSupplier tbl)
 {
     var dto = new SupplierDTO
                   {
                       MasterId = tbl.id,
                       DateCreated = tbl.IM_DateCreated,
                       DateLastUpdated = tbl.IM_DateLastUpdated,
                       StatusId = tbl.IM_Status,
                       Name = tbl.Name,
                       Description = tbl.Description,
                       Code = tbl.Code
                   };
     return dto;
 }
Ejemplo n.º 4
0
        public ActionResult Edit(Guid? id)
        {
            var model = new SupplierDTO();
            if (id.HasValue)
            {
                var p = _supplierRepository.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);
        }
Ejemplo n.º 5
0
 public Supplier Map(SupplierDTO dto)
 {
     if (dto == null) return null;
     var supplier = Mapper.Map<SupplierDTO, Supplier>(dto);
     return supplier;
 }