public IHttpActionResult Add(TOURIS_TV_SOSMED sosmedView) { ApiResData res = new ApiResData(); try { if (!ModelState.IsValid) { rs.SetErrorStatus(eFunc.fg.SFailed); resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Save, new Exception(eFunc.fg.DataIsntValid))); return(Content(HttpStatusCode.NotFound, resObj)); } TOURIS_TM_SOSMED sosmed = new TOURIS_TM_SOSMED(); sosmed.TYPE = sosmedView.TYPE; sosmed.NAME = sosmedView.NAME; sosmed.DESCRIPTION = sosmedView.DESCRIPTION; sosmed.ICON = sosmedView.ICON; sosmed.URL = sosmedView.URL; sosmed.DATA_EMBED = sosmedView.DATA_EMBED; sosmed.HEIGHT = sosmedView.HEIGHT; sosmed.WIDTH = sosmedView.WIDTH; sosmed.DATA_WIDGET_ID = sosmedView.DATA_WIDGET_ID; sosmed.CREATED_BY = sosmedView.CREATED_BY; sosmed.CREATED_TIME = sosmedView.CREATED_TIME; sosmed.ROW_STATUS = eStat.fg.IsActive; rs = repo.Add(sosmed); if (rs.IsSuccess) { rs.SetSuccessStatus(); } else { rs.SetErrorStatus(eFunc.fg.SFailed); } resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Save, null)); return(Content(HttpStatusCode.OK, resObj)); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Save, new Exception(eFunc.fg.SFailed))); return(Content(HttpStatusCode.BadRequest, resObj)); } }
public ActionResult ActionCreate(SBH_TM_SOSMED sosmedView, HttpPostedFileBase postedFile) { try { string physicalPath = ""; if (postedFile != null) { string ImageName = System.IO.Path.GetFileName(postedFile.FileName); //file2 to store path and url physicalPath = Server.MapPath("~" + Common.GetPathFolderImg() + ImageName); sosmedView.PHOTO_PATH = Common.GetPathFolderImg() + ImageName; } sosmedView.LAST_MODIFIED_BY = Session["UserId"].ToString(); sosmedView.LAST_MODIFIED_TIME = DateTime.Now; rs = repo.Add(sosmedView); if (rs.IsSuccess) { if (physicalPath != "") { postedFile.SaveAs(physicalPath); } rs.SetSuccessStatus("Data has been created successfully"); TempData["msgSuccess"] = rs.MessageText; } else { rs.SetErrorStatus("Data failed to created"); TempData["msgError"] = rs.MessageText; } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); rs.SetErrorStatus("Data failed to created"); TempData["msgError"] = rs.MessageText; } return(RedirectToAction("Index")); }