public bool UpdateAsync(StarStudent model) { using (var conn = DapperFactory.GetConnection()) { List <string> removeFields = new List <string> { "Id", "CreateTime", "Status" }; var fields = model.ToFields(removeFields: removeFields); if (fields == null || fields.Count == 0) { return(false); } var fieldList = new List <string>(); foreach (var field in fields) { fieldList.Add(string.Format("{0}=@{0}", field)); } model.ModifyTime = DateTime.Now; string sql = string.Format("update [StarStudent] set {0} where Id=@Id;", string.Join(",", fieldList)); return(conn.Execute(sql, model) > 0); } }
public bool InsertAsync(StarStudent model) { if (model == null) { throw new ArgumentNullException("model不能为null"); } return(_starStudentRepository.InsertAsync(model)); }
public ActionResult Edit(int id = 0) { StarStudent model = new StarStudent(); string action = "添加专访视频"; if (id > 0) { model = _starStudentService.GetByIdAsync(id); action = "修改专访视频"; } ViewBag.Action = action; return(View(model)); }
public bool UpdateAsync(StarStudent model) { if (model == null) { throw new ArgumentNullException("model不能为null"); } if (model.Id <= 0) { throw new ArgumentException("Id错误"); } return(_starStudentRepository.UpdateAsync(model)); }
public JsonResult Set(StarStudent model) { if (model == null) { return(Error("参数错误。")); } if (string.IsNullOrEmpty(model.Title)) { return(Error("专业名称不能为空。")); } var fileImg = Request.Files["fileImg"]; if (fileImg != null) { string uploadResult = UploadHelper.Process(fileImg.FileName, fileImg.InputStream); if (!string.IsNullOrEmpty(uploadResult)) { model.ImgUrl = uploadResult; } } var fileVideo = Request.Files["fileVideo"]; if (fileVideo != null) { string uploadResult = UploadHelper.Process(fileVideo.FileName, fileVideo.InputStream); if (!string.IsNullOrEmpty(uploadResult)) { model.VideoUrl = uploadResult; } } if (String.IsNullOrEmpty(model.VideoUrl)) { return(Error("视频不能为空。")); } var result = new ResultBase(); if (model.Id > 0) { result.success = _starStudentService.UpdateAsync(model); } else { result.success = _starStudentService.InsertAsync(model); } return(Json(result)); }
public bool InsertAsync(StarStudent model) { using (var conn = DapperFactory.GetConnection()) { var fields = model.ToFields(removeFields: new List <string> { "Id" }); if (fields == null || fields.Count == 0) { return(false); } model.CreateTime = DateTime.Now; model.ModifyTime = DateTime.Now; model.Status = 1; string sql = string.Format("insert into [StarStudent] ({0}) values ({1});", string.Join(",", fields), string.Join(",", fields.Select(n => "@" + n))); return(conn.Execute(sql, model) > 0); } }