Example #1
0
        public ActionResult Edit(SeasonViewModel model)
        {
            try
            {
              // var entity = _dtoToEntityMapping.Map(model);
                var entity = 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"] = "Season Added successfully";
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                DropDowns();
                return View(model);
            }
        }
Example #2
0
 private Season Map(SeasonViewModel model)
 {
     return new Season(model.MasterId)
         {
             Code = model.Code,
             Name = model.Name,
             CommodityProducer = _commodityProducerRepository.GetById(model.CommodityProducerId),
             Description = model.Description,
             EndDate = model.EndDate,
             StartDate = model.StartDate,
            
         };
 }
Example #3
0
 public ActionResult Edit(Guid? id)
 {
     //var model = new SeasonDTO();
     var model = new SeasonViewModel();
     if (id.HasValue)
     {
        
         var p = _seasonRepository.GetById(id.Value);
         if (p != null)
         {
             model.MasterId = id.Value;
             model.Code = p.Code;
             model.Name = p.Name;
             model.CommodityProducerId = p.CommodityProducer.Id;
             model.Description = p.Description;
             model.StartDate = DateTime.Now;
             model.EndDate = DateTime.Now;
         }
        // model = _masterDataToDtoMapping.Map(p);
        
      
     }
     DropDowns();
     if (model.MasterId == Guid.Empty)
     {
         model.MasterId = Guid.NewGuid();
         model.EndDate = DateTime.Now;
         model.StartDate = DateTime.Now;
     }
     return View(model);
 }