示例#1
0
        public static MESpecialistType ToMESpecialistType(this SpecialistTypeViewModel dto)
        {
            MESpecialistType entity = new MESpecialistType();

            entity.CopyPropertiesFrom(dto);
            return(entity);
        }
        public ActionResult Save(SpecialistTypeViewModel dto)
        {
            ViewBag.ActiveMenu = "specialist-type-index";
            var isCreate = true;

            try
            {
                if (!dto.MESpecialistTypeID.HasValue)
                {
                    _specialistTypeService.Create(dto);
                    TempData["Message"] = "Tạo mới loại chuyên khoa thành công.";
                }
                else
                {
                    isCreate = false;
                    _specialistTypeService.Update(dto);
                    TempData["Message"] = "Cập nhật loại chuyên khoa thành công.";
                }
                TempData["Success"] = true;
                return(Redirect("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Success = false;
                ViewBag.Message = isCreate ? "Tạo mới loại chuyên khoa thất bại, vui lòng thử lại." : "Cập nhật loại chuyên khoa thất bại, vui lòng thử lại.";
                return(View("Detail", dto));
            }
        }
        public ActionResult Create()
        {
            ViewBag.ActiveMenu = "specialist-type-index";
            SpecialistTypeViewModel specialist = new SpecialistTypeViewModel();

            return(View("Detail", specialist));
        }
        public static SpecialistTypeViewModel ToSpecialistTypeViewModel(this MESpecialistType entity)
        {
            if (entity == null)
            {
                return(null);
            }
            SpecialistTypeViewModel dto = new SpecialistTypeViewModel();

            dto.CopyPropertiesFrom(entity);
            dto.MESpecialistTypeID = entity.MESpecialistTypeID;
            return(dto);
        }
示例#5
0
 public void Create(SpecialistTypeViewModel dto)
 {
     try
     {
         _specialistTypeRepository.Add(dto.ToMESpecialistType());
         _unitOfWork.Commit();
     }
     catch (Exception ex)
     {
         _logService.Create(ex);
         throw ex;
     }
 }
示例#6
0
        public SpecialistTypeViewModel Update(SpecialistTypeViewModel dto)
        {
            try
            {
                var entity = _specialistTypeRepository.GetSingleById(dto.MESpecialistTypeID.GetValueOrDefault());
                if (entity == null)
                {
                    throw new Exception("Object not found!");
                }
                entity.CopyPropertiesFrom(dto);

                _specialistTypeRepository.Update(entity);
                _unitOfWork.Commit();

                return(Get(dto.MESpecialistTypeID.GetValueOrDefault()));
            }
            catch (Exception ex)
            {
                _logService.Create(ex);
                throw ex;
            }
        }