private static PayableInvoiceDetail getEntityByModel(PayableInvoiceDetailModel model, int count)
        {
            if (model == null)
                return null;

            PayableInvoiceDetail entity = new PayableInvoiceDetail();
            if (count == 0)
            {
                entity.CreateBy = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
            }
            else
            {
                entity.CreateBy = model.CreateBy;
                entity.CreateDate = model.CreateDate;
            }

            entity.Amount = model.Amount;
            entity.CodeCombinationId = model.CodeCombinationId;
            entity.Description = model.Description;
            entity.Id = model.Id;
            entity.InvoiceId = model.InvoiceId;
            entity.UpdateBy = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;

            return entity;
        }
        public ActionResult AddNewPartial(PayableInvoiceDetailModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (SessionHelper.PayableInvoice != null)
                    {
                        if (SessionHelper.PayableInvoice.InvoiceDetail != null && SessionHelper.PayableInvoice.InvoiceDetail.Count > 0)
                            model.Id = SessionHelper.PayableInvoice.InvoiceDetail.LastOrDefault().Id + 1;
                        else
                            model.Id = 1;
                    }
                    else
                        model.Id = 1;

                    PayableInvoiceHelper.Insert(model);
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
                ViewData["EditError"] = "Please, correct all errors.";
            return PartialView("_Detail", PayableInvoiceHelper.GetInvoiceDetail());
        }
 public ActionResult UpdatePartial(PayableInvoiceDetailModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             PayableInvoiceHelper.UpdateInvoiceDetail(model);
         }
         catch (Exception e)
         {
             ViewData["EditError"] = e.Message;
         }
     }
     else
         ViewData["EditError"] = "Please, correct all errors.";
     return PartialView("_Detail", PayableInvoiceHelper.GetInvoiceDetail());
 }
 public ActionResult DeletePartial(PayableInvoiceDetailModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             PayableInvoiceModel invoice = SessionHelper.PayableInvoice;
             PayableInvoiceHelper.DeleteInvoiceDetail(model);
             SessionHelper.PayableInvoice = invoice;
             IList<PayableInvoiceDetailModel> invoiceDetail = PayableInvoiceHelper.GetInvoiceDetail();
             return PartialView("_Detail", invoiceDetail);
         }
         catch (Exception e)
         {
             ViewData["EditError"] = e.Message;
         }
     }
     else
         ViewData["EditError"] = "Please, correct all errors.";
     return PartialView("_Detail");
     //return PartialView("_Detail", InvoiceHelper.GetInvoiceDetail());
 }
 public static void DeleteInvoiceDetail(PayableInvoiceDetailModel model)
 {
     PayableInvoiceModel invoice = SessionHelper.PayableInvoice;
     PayableInvoiceDetailModel invoiceDetail = invoice.InvoiceDetail.FirstOrDefault(x => x.Id == model.Id);
     invoice.InvoiceDetail.Remove(invoiceDetail);
 }
        public static void UpdateInvoiceDetail(PayableInvoiceDetailModel model)
        {
            PayableInvoiceModel invoice = SessionHelper.PayableInvoice;

            invoice.InvoiceDetail.FirstOrDefault(x => x.Id == model.Id).CodeCombinationId = model.CodeCombinationId;
            invoice.InvoiceDetail.FirstOrDefault(x => x.Id == model.Id).Amount = model.Amount;
            invoice.InvoiceDetail.FirstOrDefault(x => x.Id == model.Id).Description = model.Description;
        }
 public static void Insert(PayableInvoiceDetailModel model)
 {
     PayableInvoiceModel invoice = SessionHelper.PayableInvoice;
     invoice.InvoiceDetail.Add(model);
 }