public ActionResult Create()
 {
     InvoiceSourceViewModel model = new InvoiceSourceViewModel();
     model.SOBId = SessionHelper.SOBId;
     model.CodeCombinations = CodeCombinationHelper.GetAccounts(SessionHelper.SOBId, model.StartDate, model.EndDate);
     return View("Edit", model);
 }
        private static InvoiceSource getEntityByModel(InvoiceSourceViewModel model)
        {
            if (model == null) return null;
            InvoiceSource entity = new InvoiceSource();

            entity.CodeCombinationId = model.CodeCombinationId;
            entity.StartDate = model.StartDate;
            entity.EndDate = model.EndDate;
            entity.Description = model.Description;
            entity.Id = model.Id;
            entity.SOBId = model.SOBId;
            if (model.Id == 0)
            {
                entity.CompanyId = AuthenticationHelper.CompanyId.Value;
                entity.CreateBy = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
            }
            else
            {
                entity.CompanyId = model.CompanyId;
                entity.CreateBy = model.CreateBy;
                entity.CreateDate = model.CreateDate;
            }
            entity.UpdateDate = DateTime.Now;
            entity.UpdateBy = AuthenticationHelper.UserId;

            return entity;
        }
     public static string SaveInvoiceSource(InvoiceSourceViewModel model)
 {
         if (model.Id > 0)
         {
             return service.Update(getEntityByModel(model));
         }
         else
         {
             return service.Insert(getEntityByModel(model));
         }
     }
 public ActionResult Edit(InvoiceSourceViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             string result = InvoiceSourceHelper.SaveInvoiceSource(model);
             return RedirectToAction("Index");
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("error", ex.Message);
         }
         
     }
     return View(model);
 }
 public static InvoiceSourceViewModel GetInvoiceSource(string id)
 {
     InvoiceSourceViewModel invoiceSource = new InvoiceSourceViewModel
         (service.GetSingle(id, AuthenticationHelper.CompanyId.Value));
     return invoiceSource;
 }