예제 #1
0
        public ActionResult Edit(ShiftDTO model)
        {
            try
            {
                model.StartTime = DateTime.Parse(model.StartTimeString);
                model.EndTime = DateTime.Parse(model.EndTimeString);
                var entity = _dtoToEntityMapping.Map(model);

                var vri = _shiftRepository.Validate(entity);
                if (vri.IsValid)
                {
                    _shiftRepository.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"] = "Shift Added successfully";
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
               
                return View(model);
            }
        }
예제 #2
0
 public Shift Map(ShiftDTO dto)
 {
     if (dto == null) return null;
     var shift = Mapper.Map<ShiftDTO, Shift>(dto);
     return shift;
 }
예제 #3
0
 public ActionResult Edit(Guid? id)
 {
     var model = new ShiftDTO();
     if (id.HasValue)
     {
         var p = _shiftRepository.GetById(id.Value);
         if (p != null)
             model = _masterDataToDtoMapping.Map(p);
         model.MasterId = id.Value;
        
     }
    
     if (model.MasterId == Guid.Empty)
     {
         model.MasterId = Guid.NewGuid();
         model.StartTime = DateTime.Now;
         model.EndTime = DateTime.Now;
     }
     return View(model);
 }