public JsonResult _Save(Q_VideoTemplate_De model) { ResponseBase res = new ResponseBase(); try { res = BLLVideoTemplate_De.Instance.InsertOrUpdate(AppGlobal.Connectionstring, model); if (!res.IsSuccess) { JsonDataResult.Result = "ERROR"; JsonDataResult.ErrorMessages.AddRange(res.Errors); } else { JsonDataResult.Result = "OK"; } } catch (Exception ex) { throw (ex); } return(Json(JsonDataResult)); }
private void SaveDetail() { try { int Id = 0; int.TryParse(gridViewChild.GetRowCellValue(gridViewChild.FocusedRowHandle, "Id").ToString(), out Id); if (string.IsNullOrEmpty(gridViewChild.GetRowCellValue(gridViewChild.FocusedRowHandle, "Index").ToString())) { MessageBox.Show("Vui lòng nhập số thứ tự.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrEmpty(gridViewChild.GetRowCellValue(gridViewChild.FocusedRowHandle, "VideoId").ToString())) { MessageBox.Show("Vui lòng chọn video.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var obj = new Q_VideoTemplate_De(); obj.Id = Id; obj.TemplateId = temId; obj.Index = Convert.ToInt32(gridViewChild.GetRowCellValue(gridViewChild.FocusedRowHandle, "Index").ToString()); obj.VideoId = Convert.ToInt32(gridViewChild.GetRowCellValue(gridViewChild.FocusedRowHandle, "VideoId").ToString()); var rs = BLLVideoTemplate_De.Instance.InsertOrUpdate(connect, obj); if (rs.IsSuccess) { LoadGridDetail(); } else { MessageBox.Show(rs.Errors[0].Message, rs.Errors[0].MemberName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { } }
public ResponseBase InsertOrUpdate(Q_VideoTemplate_De model) { var rs = new ResponseBase(); using (var db = new QMSSystemEntities()) { try { if (model.Id == 0) { db.Q_VideoTemplate_De.Add(model); } else { var obj = db.Q_VideoTemplate_De.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id); if (obj != null) { obj.TemplateId = model.TemplateId; obj.VideoId = model.VideoId; obj.Index = model.Index; } } db.SaveChanges(); rs.IsSuccess = true; } catch (Exception) { rs.IsSuccess = false; rs.Errors.Add(new Error() { MemberName = "Lỗi nhập liệu", Message = "Lỗi CSDL." }); } return(rs); } }