Exemplo n.º 1
0
        public ActionResult Create(HospitalViewModel hospital)
        {
            if (ModelState.IsValid)
            {
                var hospitalDomain = Mapper.Map <HospitalViewModel, Hospital>(hospital);
                hospitalDomain.DataCadastro = DateTime.Now;

                _hospitalRepository.Add(hospitalDomain);
                return(RedirectToAction("Index"));
            }
            return(View(hospital));
        }
        /// <summary>
        /// 新增医院
        /// </summary>
        /// <param name="model">医院信息</param>
        /// <returns>是否成功</returns>
        public async Task<OutputBase> Add(AdminHospitalDto model)
        {
            if (await _repository.GetHospitalByName(model.HospitalName) != null)
                return OutputBase.Fail("同名医院已存在");

            var entity = new Hospital
            {
                CityId = model.CityId,
                HospitalName = model.HospitalName
            };
            _repository.Add(entity);

            return _unitWork.Commit() ? OutputBase.Success("新增成功") : OutputBase.Fail("新增失败");
        }