示例#1
0
        public static int CreateInsurance(InsuranceCreateViewModel model, string username)
        {
            Entities entities = new Entities();
            DateTime current  = DateTime.Now;

            Assets insurance = new Assets();

            insurance.AssetName   = model.Name;
            insurance.Value       = model.Value.Value;
            insurance.StartDate   = model.StartDate.Value;
            insurance.EndDate     = model.EndDate.Value;
            insurance.Note        = model.Note;
            insurance.CreatedDate = current;
            insurance.CreatedBy   = Constants.Constants.USER;
            insurance.AssetType   = (int)Constants.Constants.ASSET_TYPE.INSURANCE;
            insurance.Username    = username;

            Expenses expense = new Expenses();

            expense.Name        = "Đóng bảo hiểm " + insurance.AssetName;
            expense.Value       = model.Expense.Value;
            expense.StartDate   = model.StartDate.Value;
            expense.EndDate     = model.EndDate.Value;
            expense.CreatedDate = current;
            expense.CreatedBy   = Constants.Constants.USER;
            expense.ExpenseType = (int)Constants.Constants.EXPENSE_TYPE.INSURANCE;
            expense.Username    = username;

            insurance.Expenses1.Add(expense);
            entities.Assets.Add(insurance);

            return(entities.SaveChanges());
        }
示例#2
0
        public ActionResult _InsuranceForm(InsuranceCreateViewModel model)
        {
            if (model.EndDate < DateTime.Now)
            {
                ModelState.AddModelError("CheckEndDate", "Hợp đồng bảo hiểm này đã hết hạn, vui lòng chỉ nhập hợp đồng bảo hiểm đang hiệu lực");
            }

            if (model.StartDate > DateTime.Now)
            {
                ModelState.AddModelError("CheckStartDate", "Ngày bắt đầu phải nhỏ hơn ngày hiện tại.");
            }

            if (model.Expense * CarLiabilityQueries.Helper.CalculateTimePeriod(model.StartDate.Value, model.EndDate.Value) >= model.Value)
            {
                ModelState.AddModelError("CheckValueAndTotalExpenseError", "Tổng số tiền đóng phải nhỏ hơn tiền thụ hưởng");
            }

            if (ModelState.IsValid)
            {
                int result = InsuranceQueries.CreateInsurance(model, UserQueries.GetCurrentUsername());
                if (result > 0)
                {
                    return(Content("success"));
                }
                else
                {
                    return(Content("failed"));
                }
            }
            else
            {
                return(PartialView(model));
            }
        }