public IActionResult Create(CulturalViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { if (_dbContext.Information.Any(x => x.Title == model.Title)) { response.SetFailed("标题名称已存在"); return(Ok(response)); } var entity = new Information(); entity.State = model.State; entity.StartTime = Convert.ToDateTime(model.StartTime); entity.Title = model.Title; entity.Introduce = model.Introduce; entity.Photo = model.Photo; entity.Picture = model.Picture; entity.InformationUuid = Guid.NewGuid(); entity.IsDeleted = 0; //entity.AddPeople = AuthContextService.CurrentUser.LoginName; //entity.AddTime = DateTime.Now; _dbContext.Information.Add(entity); int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("添加", "成功:添加:景区资讯列表数据", _dbContext); } response.SetSuccess(); return(Ok(response)); } }
public IActionResult Edit(CulturalViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { var entity = _dbContext.Information.FirstOrDefault(x => x.InformationUuid == model.InformationUuid); if (entity == null) { response.SetFailed("该信息不存在"); return(Ok(response)); } if (_dbContext.Information.Any(x => x.Title == model.Title && x.InformationUuid != model.InformationUuid)) { response.SetFailed("标题已存在"); return(Ok(response)); } entity.State = model.State; entity.StartTime = Convert.ToDateTime(model.StartTime); entity.Title = model.Title; entity.Introduce = model.Introduce; entity.Photo = model.Photo; entity.Picture = model.Picture; int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("编辑", "成功:编辑:景区资讯列表数据", _dbContext); } return(Ok(response)); } }
public IActionResult Edit(CulturalViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { var entity = _dbContext.CulturalIntroduc.FirstOrDefault(x => x.CulturalIntroducUuid == model.CulturalIntroducUuid); if (entity == null) { response.SetFailed("该信息不存在"); return(Ok(response)); } if (_dbContext.CulturalIntroduc.Any(x => x.Title == model.Title && x.CulturalIntroducUuid != model.CulturalIntroducUuid)) { response.SetFailed("标题已存在"); return(Ok(response)); } entity.Title = model.Title; entity.Content = model.Content; entity.Cover = model.Cover; entity.IsRelease = model.IsRelease; entity.ReleaseTime = Convert.ToDateTime(model.ReleaseTime); entity.Photo = model.Photo; int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("编辑", "成功:编辑:人文介绍列表数据", _dbContext); } return(Ok(response)); } }
public async Task <IActionResult> Create(CulturalViewModel vm) { if (ModelState.IsValid) { var result = await _services.CreateAsync(_mapper.Map <DirectoryDTO>(vm)); return(result.IsValid ? RedirectToAction("Index") : _oops.OutPutError("Cultural", "Index", result.ErrorsList)); } return(View(vm)); }
public async Task <IActionResult> UpdateConfirmed(CulturalViewModel vm) { if (ModelState.IsValid) { if (vm.HashId == null) { return(NotFound()); } var result = await _services.UpdateAsync(_mapper.Map <DirectoryDTO>(vm)); return(result.IsValid ? RedirectToAction("Index") : _oops.OutPutError("Cultural", "Index", result.ErrorsList)); } return(View(vm)); }
public IActionResult Create(CulturalViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { if (_dbContext.CulturalIntroduc.Any(x => x.Title == model.Title)) { response.SetFailed("标题名称已存在"); return(Ok(response)); } var entity = new CulturalIntroduc(); entity.IsRelease = model.IsRelease; if (!string.IsNullOrEmpty(model.ReleaseTime.ToString())) { entity.ReleaseTime = Convert.ToDateTime(model.ReleaseTime); } entity.Title = model.Title; entity.Content = model.Content; entity.Cover = model.Cover; entity.CulturalIntroducUuid = Guid.NewGuid(); entity.IsDeleted = 0; entity.AddPeople = AuthContextService.CurrentUser.LoginName; entity.AddTime = DateTime.Now; entity.Photo = model.Photo; _dbContext.CulturalIntroduc.Add(entity); int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("添加", "成功:添加:人文介绍列表数据", _dbContext); } response.SetSuccess(); return(Ok(response)); } }