Пример #1
0
        public ActionResult Create(SeasonDTO model)
        {
            try
            {
                var entity = _dtoToEntityMapping.Map(model);

                var vri = _seasonRepository.Validate(entity);
                if (vri.IsValid)
                {
                    _seasonRepository.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++;
                    }

                    DropDowns();
                    return View(model);
                }
                TempData["msg"] = "Task completed successfully";
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                DropDowns();
                return View(model);
            }
        }
Пример #2
0
 public Season Map(SeasonDTO dto)
 {
     if (dto == null) return null;
     var s = Mapper.Map<SeasonDTO, Season>(dto);
     s.CommodityProducer = _commodityProducerRepository.GetById(dto.CommodityProducerId);
     return s;
 }
Пример #3
0
        public ActionResult Create(Guid? id)
        {
            var model = new SeasonDTO();
            if (id.HasValue)
            {
                var p = _seasonRepository.GetById(id.Value);
                if (p != null)
                    model = _masterDataToDtoMapping.Map(p);
                model.MasterId = id.Value;
                model.StartDate = DateTime.Now;
                model.EndDate = DateTime.Now;

            }
            DropDowns();
            if (model.MasterId == Guid.Empty)
            {
                model.MasterId = Guid.NewGuid();
                model.EndDate = DateTime.Now;
                model.StartDate = DateTime.Now;
            }
            return View(model);
        }