private static Withholding getEntityByModel(WithholdingModel model)
        {
            if (model == null) return null;

            Withholding entity = new Withholding();

            if (model.Id == 0)
            {
                entity.CreateBy = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
                entity.CompanyId = AuthenticationHelper.CompanyId.Value;
            }
            else
            {
                entity.CreateBy = model.CreateBy;
                entity.CreateDate = model.CreateDate;
                entity.CompanyId = model.CompanyId;
            }

            entity.Code = model.WithholdingCode;
            entity.VendorSiteId = model.VendorSiteId;
            entity.VendorId = model.VendorId;
            entity.SOBId = model.SOBId;
            entity.Rate = model.Rate;
            entity.Description = model.Description;
            entity.DateTo = model.DateTo;
            entity.DateFrom = model.DateFrom;
            entity.CodeCombinitionId = model.CodeCombinitionId;
            entity.Id = model.Id;
            entity.UpdateBy = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;
            return entity;
        }
 public static string Save(WithholdingModel model)
 {
     if (model.Id > 0)
     {
         return service.Update(getEntityByModel(model));
     }
     else
     {
         return service.Insert(getEntityByModel(model));
     }
 }
        public ActionResult AddNewInline(WithholdingModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.VendorId = SessionHelper.VendorId;
                    model.SOBId = SessionHelper.SOBId; 
                    model.CodeCombinitionId = SessionHelper.CodeCombinitionId;

                    WithholdingHelper.Save(model);
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
                ViewData["EditError"] = "Please, correct all errors.";
            return PartialView("_List", WithholdingHelper.GetWithholdings(model.SOBId, model.CodeCombinitionId, model.VendorId));
        }
 public ActionResult DeleteInline(WithholdingModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             WithholdingHelper.Delete(model.Id.ToString());
             return PartialView("_List", WithholdingHelper.GetWithholdings(model.SOBId, model.CodeCombinitionId, model.VendorId));
         }
         catch (Exception e)
         {
             ViewData["EditError"] = e.Message;
         }
     }
     else
         ViewData["EditError"] = "Please, correct all errors.";
     return PartialView("_List", WithholdingHelper.GetWithholdings(model.SOBId, model.CodeCombinitionId, model.VendorId));
 }