public JsonResult GetItem(int id) { var msg = new JMessage() { Error = false, Title = "" }; var data = _context.AddonApps.FirstOrDefault(x => x.Id == id); if (data != null) { var model = new AddonAppModel { Id = data.Id, AppCode = data.AppCode, AppTitle = data.AppTitle, AppDate = data.AppDate.HasValue ? data.AppDate.Value.ToString("dd/MM/yyyy") : null, LinkChplay = data.LinkChplay, UrlIcon = data.Icon, Status = data.Status, Note = data.Note, }; msg.Object = model; } else { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_NOT_EXITS_FILE")); } return(Json(msg)); }
public JsonResult Update(AddonAppModel obj, IFormFile icon) { var msg = new JMessage() { Error = false, Title = "" }; try { var data = _context.AddonApps.FirstOrDefault(x => x.Id == obj.Id); if (data != null) { if (icon != null) { var upload = _upload.UploadImage(icon); if (!upload.Error) { data.AppTitle = obj.AppTitle; data.AppDate = !string.IsNullOrEmpty(obj.AppDate) ? DateTime.ParseExact(obj.AppDate, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null; data.LinkChplay = obj.LinkChplay; data.Status = obj.Status; data.Note = obj.Note; data.Icon = "/uploads/images/" + upload.Object.ToString(); _context.SaveChanges(); msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_UPDATE_SUCCESS"), CommonUtil.ResourceValue("ADA_MSG_APP")); } } else { data.AppTitle = obj.AppTitle; data.AppDate = !string.IsNullOrEmpty(obj.AppDate) ? DateTime.ParseExact(obj.AppDate, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null; data.LinkChplay = obj.LinkChplay; data.Status = obj.Status; data.Note = obj.Note; _context.SaveChanges(); msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_UPDATE_SUCCESS"), CommonUtil.ResourceValue("ADA_MSG_APP")); } } else { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_NOT_EXITS"), CommonUtil.ResourceValue("ADA_MSG_EXITS_APP")); } } catch (Exception ex) { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_UPDATE_FAIL")); } return(Json(msg)); }
public JsonResult Insert(AddonAppModel obj, IFormFile icon) { var msg = new JMessage() { Error = false, Title = "" }; try { var checkExist = _context.AddonApps.FirstOrDefault(x => x.AppCode.ToLower() == obj.AppCode.ToLower()); if (checkExist != null) { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_EXITS"), CommonUtil.ResourceValue("ADA_MSG_CODE_APP")); } else { if (icon != null) { var upload = _upload.UploadImage(icon); if (!upload.Error) { var model = new AddonApp { AppCode = obj.AppCode, AppTitle = obj.AppTitle, AppDate = !string.IsNullOrEmpty(obj.AppDate) ? DateTime.ParseExact(obj.AppDate, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null, LinkChplay = obj.LinkChplay, Icon = "/uploads/images/" + upload.Object.ToString(), Status = obj.Status, Note = obj.Note }; _context.AddonApps.Add(model); _context.SaveChanges(); msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_SUCCESS"), CommonUtil.ResourceValue("ADA_MSG_APP")); } } else { var model = new AddonApp { AppCode = obj.AppCode, AppTitle = obj.AppTitle, AppDate = !string.IsNullOrEmpty(obj.AppDate) ? DateTime.ParseExact(obj.AppDate, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null, LinkChplay = obj.LinkChplay, Status = obj.Status, Note = obj.Note }; _context.AddonApps.Add(model); _context.SaveChanges(); msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_SUCCESS"), CommonUtil.ResourceValue("ADA_MSG_APP")); } } } catch (Exception ex) { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_ADD")); } return(Json(msg)); }