public ActionResult Booking() { ViewBag.BookingTypes = GetBookingTypes(); ViewBag.VehicleTypeList = GetVehicleTypes(); ViewBag.EngineTypes = GetEngineTypes(); using (GarageManagementEntities entities = new GarageManagementEntities()) { var listMakes = entities.Makes.ToList(); var userId = User.Identity.GetUserId(); var customerId = entities.Customer.FirstOrDefault(x => x.UserId == userId).Id; var booking = entities.Bookings.OrderByDescending(x => x.DueDate).FirstOrDefault(x => x.CustomerId == customerId); var model = booking != null ? new BookingView() { BookingTypeId = booking.BookingTypeId, DueDate = booking.DueDate.Value, Make = listMakes.Any(y => y.Name == booking.Make) ? booking.Make : "Other", EngineType = booking.EngineTypeId, Observation = booking.Observation, Other = listMakes.Any(y => y.Name == booking.Make) ? "" : booking.Make, VehicleType = booking.VehicleTypeId, VLC = booking.VLC, VRC = booking.VRC, Licence = booking.Licence, StatusName = booking.Status.Name, StatusId = booking.StatusId, Id = booking.Id, BasicCost = booking.BasicCost.HasValue ? booking.BasicCost.Value : 0, StaffId = booking.StaffId.HasValue ? booking.StaffId.Value : 0 } : null; return(View(model)); } }
public JsonResult addProducts(int bookingId, List <Prods> prods) { using (GarageManagementEntities entities = new GarageManagementEntities()) { if (prods != null) { foreach (var item in prods) { var prod = entities.ServicesAndParts.FirstOrDefault(x => x.Id == item.id); var model = new booking_cost() { BookingId = bookingId, Price = prod.Price, Qtd = item.qtd, ServicesAndPartsId = item.id }; entities.booking_cost.Add(model); } entities.SaveChanges(); } } return(Json(new { result = "success", data = GetProductsByOrder(bookingId) }, JsonRequestBehavior.AllowGet)); }
public ActionResult EditService(ServicesAndPartsView model) { if (ModelState.IsValid) { using (GarageManagementEntities entities = new GarageManagementEntities()) { var part = entities.ServicesAndParts.FirstOrDefault(x => x.Id == model.Id); var newPart = new ServicesAndParts() { Name = model.Name, Price = model.Price }; if (model.Id > 0) { part.Name = model.Name; part.Price = model.Price; } else { entities.ServicesAndParts.Add(newPart); } entities.SaveChanges(); return(RedirectToAction("ConfirmServicesAndParts", "Manage")); } } return(View(model)); }
public ActionResult ModalConfirmServicesAndParts() { using (GarageManagementEntities entities = new GarageManagementEntities()) { var products = entities.ServicesAndParts.ToList(); return(View(products)); } }
public void RemoveProd(int id) { using (GarageManagementEntities entities = new GarageManagementEntities()) { var model = entities.booking_cost.FirstOrDefault(x => x.Id == id); entities.booking_cost.Remove(model); entities.SaveChanges(); } }
public ActionResult Staff() { var data = new List <Staff>(); using (GarageManagementEntities entities = new GarageManagementEntities()) { data = entities.Staff.ToList(); } return(View(data)); }
public ActionResult GetBookings() { var data = new List <Bookings>(); using (GarageManagementEntities entities = new GarageManagementEntities()) { data = entities.Bookings.ToList(); } return(Json(new { data = data }, JsonRequestBehavior.AllowGet)); }
public ActionResult BookingsAdmin() { var data = new List <Bookings>(); using (GarageManagementEntities entities = new GarageManagementEntities()) { data = entities.Bookings.Include("Customer").Include("BookingTypes").Include("Status").Include("Staff").ToList(); } return(View(data)); }
public ActionResult ServicesAndParts() { var data = new List <ServicesAndParts>(); using (GarageManagementEntities entities = new GarageManagementEntities()) { data = entities.ServicesAndParts.ToList(); } return(View(data)); }
public object GetProductsByOrder(int id) { var items = new List <booking_cost>(); using (GarageManagementEntities entities = new GarageManagementEntities()) { items = entities.booking_cost.Include("Bookings").Include("ServicesAndParts").Where(x => x.BookingId == id).ToList(); } return(items.Select(x => new { Id = x.Id, Name = x.ServicesAndParts.Name, Price = x.Price, Qtd = x.Qtd }).ToList()); }
public JsonResult GetDisabledDates() { string[] dates; using (GarageManagementEntities entities = new GarageManagementEntities()) { dates = entities.Database.SqlQuery <string>("select convert(varchar, DueDate, 10) from Bookings group by DueDate having COUNT(*) >= 5") .ToList().ToArray(); } // dates = new string[] { "08/17/2020", "08/18/2020" }; return(Json(new { result = "success", list = dates }, JsonRequestBehavior.AllowGet)); }
public ActionResult Print(int id) { var model = new PrintView(); using (GarageManagementEntities entities = new GarageManagementEntities()) { model.Products = entities.booking_cost.Include("ServicesAndParts").Where(x => x.BookingId == id).ToList(); model.Booking = entities.Bookings.Include("Customer").Include("BookingTypes").FirstOrDefault(x => x.Id == id); } return(View(model)); }
public JsonResult GetMakes(int type) { Dictionary <string, string> items = new Dictionary <string, string>(); using (GarageManagementEntities entities = new GarageManagementEntities()) { items = entities.Makes.Where(x => x.VehicleTypeId == type).ToDictionary(t => t.Name, t => t.Name); } items.Add("Other", "0"); return(Json(new { result = "success", list = items }, JsonRequestBehavior.AllowGet)); }
public ActionResult RemoveService(int id) { using (GarageManagementEntities entities = new GarageManagementEntities()) { var model = entities.ServicesAndParts.FirstOrDefault(x => x.Id == id); entities.ServicesAndParts.Remove(model); entities.SaveChanges(); } return(RedirectToAction("ServicesAndParts", "Manage")); }
public ActionResult RemoveStaff(int id) { using (GarageManagementEntities entities = new GarageManagementEntities()) { var model = entities.Staff.FirstOrDefault(x => x.Id == id); var user = UserManager.FindById(model.UserId); entities.Staff.Remove(model); entities.SaveChanges(); UserManager.Delete(user); } return(RedirectToAction("Staff", "Account")); }
private List <SelectListItem> GetVehicleTypes() { List <SelectListItem> VehicleTypes; using (GarageManagementEntities entities = new GarageManagementEntities()) { VehicleTypes = entities.VehicleType.Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString(), }).ToList(); } return(VehicleTypes); }
private List <SelectListItem> GetEngineTypes() { List <SelectListItem> items; using (GarageManagementEntities entities = new GarageManagementEntities()) { items = entities.EngineType.Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString(), }).ToList(); } return(items); }
public ActionResult EditService(int id) { var model = new ServicesAndPartsView(); using (GarageManagementEntities entities = new GarageManagementEntities()) { var part = entities.ServicesAndParts.FirstOrDefault(x => x.Id == id); if (part != null) { model = new ServicesAndPartsView() { Name = part.Name, Price = part.Price.Value, Id = part.Id, }; } } return(View(model)); }
// // GET: /Account/Register public ActionResult RegisterStaff(int?id) { RegisterViewModel model = null; if (id.HasValue && id.Value > 0) { model = new RegisterViewModel(); using (GarageManagementEntities entities = new GarageManagementEntities()) { var staff = entities.Staff.FirstOrDefault(x => x.Id == id); var user = entities.AspNetUsers.FirstOrDefault(x => x.Id == staff.UserId); model.isStaff = true; model.Email = user.Email; model.Name = staff.Name; model.Surname = staff.Surname; model.BirthDate = staff.BirthDate.Value; model.ContactNumber = staff.ContactNumber; model.Id = staff.Id; } } return(View(model)); }
public ActionResult EditBooking(int id) { var model = new BookingView(); using (GarageManagementEntities entities = new GarageManagementEntities()) { var listMakes = entities.Makes.ToList(); var booking = entities.Bookings.FirstOrDefault(x => x.Id == id); model = new BookingView() { BookingTypeId = booking.BookingTypeId, DueDate = booking.DueDate.Value, Make = listMakes.Any(y => y.Name == booking.Make) ? booking.Make : "Other", EngineType = booking.EngineTypeId, Observation = booking.Observation, Other = listMakes.Any(y => y.Name == booking.Make) ? "" : booking.Make, VehicleType = booking.VehicleTypeId, VLC = booking.VLC, VRC = booking.VRC, Licence = booking.Licence, StatusName = booking.Status.Name, StatusId = booking.StatusId, Id = booking.Id, BasicCost = booking.BasicCost.HasValue ? booking.BasicCost.Value : 0, StaffId = booking.StaffId.HasValue ? booking.StaffId.Value : 0 }; } ViewBag.Staffs = GetAvailableStaff(model.DueDate); ViewBag.Status = GetStatus(); ViewBag.BookingTypes = GetBookingTypes(); ViewBag.VehicleTypeList = GetVehicleTypes(); ViewBag.EngineTypes = GetEngineTypes(); return(View(model)); }
private List <SelectListItem> GetAvailableStaff(DateTime date) { List <SelectListItem> items; using (GarageManagementEntities entities = new GarageManagementEntities()) { var staffs = entities.Database.SqlQuery <int>(string.Format(@"select id from ( select a.id, case when b.BookingTypeId != 4 then 1 when b.BookingTypeId is null then 0 else 2 end as qt, b.BookingTypeId from Staff a left join Bookings b on b.StaffId = a.Id and (b.DueDate = '{0}' or b.DueDate is null) )b group by id having SUM(qt) < 4", date.ToString("yyyyMMdd"))).ToList(); items = entities.Staff.Where(x => staffs.Contains(x.Id)).Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString(), }).ToList(); } items.Add(new SelectListItem() { Text = "Please select one Staff", Value = "0" }); return(items); }
public ActionResult Booking(BookingView model) { if (model.Make == "Other" && string.IsNullOrEmpty(model.Other)) { ModelState.AddModelError("Other", "'Other' field is mandatory if you have selected Other on Make's Dropdownlist."); } if (model.Id > 0 && model.BasicCost == 0) { ModelState.AddModelError("BasicCost", "'BasicCost' field is mandatory if you are changing an existent booking."); } if (ModelState.IsValid) { using (GarageManagementEntities entities = new GarageManagementEntities()) { var userId = User.Identity.GetUserId().ToString(); var customerId = entities.Customer.FirstOrDefault(x => x.UserId == userId).Id; var newBooking = new Bookings() { BookingTypeId = model.BookingTypeId, DueDate = model.DueDate, Make = model.Other ?? model.Make, CustomerId = customerId, Observation = model.Observation, StatusId = 1, EngineTypeId = model.EngineType, VRC = model.VRC, VLC = model.VLC, Licence = model.Licence, VehicleTypeId = model.VehicleType }; if (model.Id > 0) { var oldBooking = entities.Bookings.FirstOrDefault(x => x.Id == model.Id); oldBooking.BookingTypeId = model.BookingTypeId; oldBooking.DueDate = model.DueDate; oldBooking.Make = model.Other ?? model.Make; oldBooking.CustomerId = customerId; oldBooking.Observation = model.Observation; oldBooking.StatusId = model.StatusId; oldBooking.StaffId = model.StaffId; oldBooking.EngineTypeId = model.EngineType; oldBooking.VRC = model.VRC; oldBooking.VLC = model.VLC; oldBooking.Licence = model.Licence; oldBooking.VehicleTypeId = model.VehicleType; oldBooking.BasicCost = model.BasicCost; } else { entities.Bookings.Add(newBooking); } entities.SaveChanges(); return(RedirectToAction("ConfirmBooking", "Manage")); } } ViewBag.Staffs = GetAvailableStaff(model.DueDate); ViewBag.Status = GetStatus(); ViewBag.BookingTypes = GetBookingTypes(); ViewBag.VehicleTypeList = GetVehicleTypes(); ViewBag.EngineTypes = GetEngineTypes(); if (model.Id > 0) { return(View("EditBooking", model)); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (!model.isStaff) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); UserManager.AddToRole(user.Id, "Customer"); using (GarageManagementEntities entities = new GarageManagementEntities()) { entities.Customer.Add(new Customer() { Name = model.Name, Surname = model.Surname, BirthDate = model.BirthDate, ContactNumber = model.ContactNumber, UserId = user.Id }); entities.SaveChanges(); } } else { UserManager.AddToRole(user.Id, "Staff"); using (GarageManagementEntities entities = new GarageManagementEntities()) { entities.Staff.Add(new Staff() { Name = model.Name, Surname = model.Surname, BirthDate = model.BirthDate, ContactNumber = model.ContactNumber, UserId = user.Id }); entities.SaveChanges(); } } ViewBag.User = user; if (model.isStaff) { return(RedirectToAction("RegisterStaffConfirmation", "Home")); } return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form if (model.isStaff) { return(View("RegisterStaff", model)); } return(View(model)); }