public async Task <IActionResult> Create(CreateBillModel model) { if (!LogedIn()) { return(RedirectToRoute("Home")); } if (ModelState.IsValid) { Vehicle v = _context.Vehicles.Find(model.SelectedVehicle); Service s = _context.Service.Find(model.SelectedService); Bill bill = new Bill { Service = s.Name, Vehicle = v, DateTime = model.DateTime, Provider = model.Provider, Cost = model.Cost }; _context.Add(bill); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } model.FillVehiclesAndServices(_context, CompanyId); return(View(model)); }
public async Task <IHttpActionResult> Create(CreateBillModel model) { IHttpActionResult httpActionResult; if (CheckPhoneNumber.CheckCorrectPhoneNumber(model.BuyerPhone)) { error.Add("Vui lòng nhập đúng sdt!"); httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error); } if (error.errors.Count == 0 && CheckPhoneNumber.CheckCorrectPhoneNumber(model.BuyerPhone)) { this._userManager = new ApplicationUserManager(new UserStore <Account>(this.db)); Bill bill = new Bill(); bill.BillCode = "HD" + RemoveSpacesAndSpecialCharacters.convertToUnSign(DateTime.Now.Date.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString()); bill.Account = await _userManager.FindByNameAsync(User.Identity.Name); bill.Branch = db.Branches.FirstOrDefault(x => x.Id == model.BranchId); bill.CreatedDate = DateTime.Now; bill.CreatedBy = User.Identity.Name; bill.BuyerName = model.BuyerName ?? model.BuyerName; bill.BuyerAddress = model.BuyerAddress ?? model.BuyerAddress; bill.BuyerPhone = model.BuyerPhone ?? model.BuyerPhone; bill.ModeOfPayment = model.ModeOfPayment ?? model.ModeOfPayment; bill = db.Bills.Add(bill); db.SaveChanges(); httpActionResult = Ok(new BillModel(bill)); } else { httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error); } return(httpActionResult); }
// GET: Bills/Create public IActionResult Create() { if (!LogedIn()) { return(RedirectToRoute("Home")); } CreateBillModel model = new CreateBillModel(); model.FillVehiclesAndServices(_context, CompanyId); return(View(model)); }
public ActionResult Create(CreateBillModel model) { try { var user = userService.GetUsersByEmail(model.EmailOfUser); var newBill = new Bill() { Id = Guid.NewGuid(), Balance = 0, BillType = (BillType)Enum.Parse(typeof(BillType), model.BillType), IBank = model.IBank, }; billService.CreateBillOnUser(user, newBill); return(RedirectToAction("Index", "Home")); } catch { return(View(model)); } }