Exemplo n.º 1
0
        public ActionResult Create(Delivery item)
        {
            IDbConnection db = new OrmliteConnection().openConn();

            try
            {
                item.entryname = item.entryname ?? "";
                item.entrycode = item.entrycode ?? "";
                //if (string.IsNullOrEmpty(item.entryname) || string.IsNullOrEmpty(item.entrycode)) return Json(new { success = false, message = tw_Lang.Common_ActionResult_MissingInfo });
                var isExist = Delivery.GetById(item.entryid, null, false);

                //Validate

                //insert / update
                if (item.entryid == 0)
                {
                    //insert
                    item.createdat = DateTime.Now;
                    item.createdby = currentUser.entryid;
                    item.updatedat = DateTime.Now;
                    item.updatedby = currentUser.entryid;
                    item.isactive  = true;
                }
                else
                {
                    //update
                    item.createdby = isExist.createdby;
                    item.updatedat = DateTime.Now;
                    item.updatedby = currentUser.entryid;
                }
                item.AddOrUpdate(currentUser.entryid, null, false);
                return(Json(new { success = true, data = item }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, message = e.Message }));
            }
            finally { db.Close(); }
        }