示例#1
0
        public ValidationMsg Save(SysTransHead objSysHead, int userID)
        {
            var vmMsg = new ValidationMsg();

            try
            {
                var tblSysHead = new Sys_TransHead
                {
                    HeadName     = objSysHead.HeadName,
                    HeadCode     = objSysHead.HeadCode,
                    HeadCategory = objSysHead.HeadCategory == "Addition" ? "AD" : "DD",
                    HeadType     = DalCommon.ReturnTransHeadType(objSysHead.HeadType),
                    IsActive     = objSysHead.IsActive == "Active",
                    SetOn        = DateTime.Now,
                    SetBy        = userID,
                    ModifiedOn   = DateTime.Now,
                    ModifiedBy   = userID,
                    IPAddress    = string.Empty
                };

                _context.Sys_TransHead.Add(tblSysHead);
                _context.SaveChanges();
                HeadID = tblSysHead.HeadID;

                vmMsg.Type = Enums.MessageType.Success;
                vmMsg.Msg  = "Save Successfully.";
            }
            catch (Exception ex)
            {
                vmMsg.Type = Enums.MessageType.Error;
                vmMsg.Msg  = "Failed to save.";
            }

            return(vmMsg);
        }
示例#2
0
        public ValidationMsg Update(SysTransHead objSysHead, int userID)
        {
            var vmMsg = new ValidationMsg();

            try
            {
                var Head = _context.Sys_TransHead.FirstOrDefault(s => s.HeadID == objSysHead.HeadID);

                if (Head != null)
                {
                    Head.HeadName     = objSysHead.HeadName;
                    Head.HeadCode     = objSysHead.HeadCode;
                    Head.HeadCategory = objSysHead.HeadCategory == "Addition" ? "AD" : "DD";
                    Head.HeadType     = DalCommon.ReturnTransHeadType(objSysHead.HeadType);
                    Head.IsActive     = objSysHead.IsActive == "Active";

                    Head.ModifiedOn = DateTime.Now;
                    Head.ModifiedBy = userID;
                }
                _context.SaveChanges();

                vmMsg.Type = Enums.MessageType.Update;
                vmMsg.Msg  = "Updated Successfully.";
            }
            catch (Exception ex)
            {
                vmMsg.Type = Enums.MessageType.Error;
                vmMsg.Msg  = "Failed to update.";
            }

            return(vmMsg);
        }
 public ActionResult TransHead(SysTransHead model)
 {
     if (model != null && model.HeadID != 0)
     {
         _vmMsg = _dalTransHead.Update(model, Convert.ToInt32(Session["UserID"]));
     }
     else
     {
         _vmMsg = _dalTransHead.Save(model, Convert.ToInt32(Session["UserID"]));
     }
     return(Json(new { HeadID = _dalTransHead.GetHeadID(), msg = _vmMsg }));
 }