public ActionResult _CarLiabilityForm(CarLiabilityCreateViewModel model)
 {
     if (model.Value > model.LiabilityValue)
     {
         ModelState.AddModelError("CheckValue", "Giá trị nợ phải nhỏ hơn tổng giá trị tiêu sản");
     }
     if (ModelState.IsValid)
     {
         int result = CarLiabilityQueries.AddCarLiability(model, UserQueries.GetCurrentUsername());
         if (result > 0)
         {
             return(Content("success"));
         }
         else
         {
             return(Content("failed"));
         }
     }
     else
     {
         return(PartialView(model));
     }
 }
        public static int AddCarLiability(CarLiabilityCreateViewModel model, string username)
        {
            DateTime current  = DateTime.Now;
            Entities entities = new Entities();

            Liabilities liability = new Liabilities();

            liability.Name             = model.Source;
            liability.Value            = model.Value.Value;
            liability.OriginalValue    = model.LiabilityValue.Value;
            liability.InterestType     = model.InterestType;
            liability.InterestRate     = model.InterestRate.Value;
            liability.InterestRatePerX = model.InterestRatePerX;
            liability.StartDate        = model.StartDate.Value;
            liability.EndDate          = model.EndDate.Value;
            liability.Note             = model.Note;
            liability.LiabilityType    = (int)Constants.Constants.LIABILITY_TYPE.CAR;
            liability.CreatedDate      = current;
            liability.CreatedBy        = Constants.Constants.USER;
            liability.Username         = username;

            entities.Liabilities.Add(liability);
            return(entities.SaveChanges());
        }