public IActionResult Create(PromotionalVideoViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { if (_dbContext.PromotionalVideo.Count(x => x.Title == model.Title) > 0) { response.SetFailed("标题已存在"); return Ok(response); } var entity = _mapper.Map<PromotionalVideoViewModel, PromotionalVideo>(model); entity.PromotionalVideoUuid = Guid.NewGuid(); entity.IsDeleted = 0; entity.AddTime = DateTime.Now; entity.AddPeople = AuthContextService.CurrentUser.DisplayName; _dbContext.PromotionalVideo.Add(entity); int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("添加", "成功:添加:宣传视频列表数据", _dbContext); } response.SetSuccess(); return Ok(response); } }
public IActionResult Edit(PromotionalVideoViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { var entity = _dbContext.PromotionalVideo.FirstOrDefault(x => x.PromotionalVideoUuid == model.PromotionalVideoUuid); if (entity == null) { response.SetFailed("不存在"); return Ok(response); } if (_dbContext.PromotionalVideo.Count(x => x.Title == model.Title && x.PromotionalVideoUuid != model.PromotionalVideoUuid) > 0) { response.SetFailed("标题已存在"); return Ok(response); } entity.Title = model.Title; entity.Cover = model.Cover; entity.ReleaseTime = model.ReleaseTime; entity.ReleaseState = model.ReleaseState; entity.Video = model.Video; entity.IsRecommend = model.IsRecommend; int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("编辑", "成功:编辑:宣传视频列表数据", _dbContext); } response = ResponseModelFactory.CreateInstance; return Ok(response); } }