public async Task <IActionResult> OnPostAsync(string[] selectedCategories) { var newCar = new Car(); if (selectedCategories != null) { newCar.CarCategories = new List <CarCategory>(); foreach (var cat in selectedCategories) { var catToAdd = new CarCategory { CategoryID = int.Parse(cat) }; newCar.CarCategories.Add(catToAdd); } } if (await TryUpdateModelAsync <Car>(newCar, "Car", i => i.Brand, i => i.Type, i => i.Price, i => i.SellingDate, i => i.SellerID)) { _context.Car.Add(newCar); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCategoryData(_context, newCar); return(Page()); }
public async Task <ActionResult <CarCategory> > PostCarCategory(CarCategory carCategory) { _context.carcategory.Add(carCategory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCarCategory", new { id = carCategory.CatgId }, carCategory)); }
public string GetFullCatLocation(CarCategory cat) { if (cat.CatLevel == 1) return db.CarCategories.FirstOrDefault(x => x.CatID == cat.CatParentID).CatName + " » " + cat.CatName; else return cat.CatName; }
public PriceCalculatorTests() { this.carCategoryCompact = new CarCategory(idCarCategory: 1, name: "Compact", dayPriceMultiplier: 1, kilometerPriceMultiplier: 0); this.carCategoryPremium = new CarCategory(idCarCategory: 2, name: "Premium", dayPriceMultiplier: 1.2, kilometerPriceMultiplier: 1); this.carCategoryMinivan = new CarCategory(idCarCategory: 3, name: "Minivan", dayPriceMultiplier: 1.7, kilometerPriceMultiplier: 1.5); this.settings = new Settings(baseDayRental: 700, kilometerPrice: 3); }
public CarCategory Add(CarCategory carCategory) { if (carCategory == null) { return(null); } try { using (var unitOfWork = new UnitOfWork(new RentCarContext())) { carCategory.DateCreated = DateTime.Now; carCategory.DateUpdated = DateTime.Now; carCategory.Deleted = false; unitOfWork.CarCategories.Add(carCategory); unitOfWork.Complete(); } } catch (Exception e) { return(null); } return(carCategory); }
public Booking RentACar(CarCategory carCategory, DateTime customerBirthDate, DateTime dateOfRentalStart, DateTime dateOfRentalEnd) { var availableCars = GetAvailableCars(carCategory, dateOfRentalStart, dateOfRentalEnd); if (!availableCars.Any()) { throw new DBItemNotFoundException("There were no available cars in the database for the specified car category and reservation dates."); } var chosenCar = availableCars.First(); if (dateOfRentalEnd < dateOfRentalStart) { throw new DateOutOfRangeException("ReturnDate for the car can not be before startdate of the booking/reservation."); } var newBooking = new Booking { Car = chosenCar, CustomerBirthDate = customerBirthDate, RentalDate = dateOfRentalStart, DateOfRentalEnd = dateOfRentalEnd, }; repos.Create(newBooking); repos.SaveChanges(); return(newBooking); }
public ActionResult edit_car(CarCategory cc) { var result = false; if (ModelState.IsValid) { var car_db = db.Cars.SingleOrDefault(c => c.Id == cc.car.Id); if (ImageUploaded.image_file_name != null) { string old_image = Path.Combine(Server.MapPath("~/uploads/car"), car_db.Image); System.IO.File.Delete(old_image); car_db.Image = ImageUploaded.image_file_name; } else { car_db.car_category_id = cc.car.car_category_id; } car_db.Model = cc.car.Model; car_db.Color = cc.car.Color; car_db.NumberOfChair = cc.car.NumberOfChair; car_db.PriceOfRent = cc.car.PriceOfRent; db.SaveChanges(); result = true; } return(Json(result, JsonRequestBehavior.AllowGet)); }
private ICollection <Car> GetAvailableCars(CarCategory carCategory, DateTime dateOfRentalStart, DateTime dateOfRentalEnd) { var carsInCategory = repos.DataSet <Car>().Where(c => c.Category == carCategory).Include(c => c.Bookings).ToList(); var availableCars = carsInCategory.Where(c => c.Bookings.All(b => !BlocksNewBooking(b, dateOfRentalStart, dateOfRentalEnd))).ToList(); return(availableCars); }
public async Task <IActionResult> PutCarCategory(string id, CarCategory carCategory) { if (id != carCategory.CatgId) { return(BadRequest()); } _context.Entry(carCategory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarCategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public CarCategory Update(CarCategory item) { //car category state that is currently modified is saved to the DB Context.Entry(item).State = EntityState.Modified; Context.SaveChanges(); return(item); }
public int GetDisplayOrder(int parentId, int display, string cal) { int res = 0; if (cal == "none") { res = (int)db.CarCategories.Where(x => x.ParentID == parentId).Max(x => x.DisplayOrder) + 1; } if (cal == "minus") { for (int i = display - 1; i > 0; i--) { CarCategory entity = db.CarCategories.SingleOrDefault(x => x.ParentID == parentId && x.DisplayOrder == i); if (entity == null) { return(i); } } return(0); } if (cal == "plus") { while (true) { display++; CarCategory entity = db.CarCategories.SingleOrDefault(x => x.ParentID == parentId && x.DisplayOrder == display); if (entity == null) { return(display); } } } return(res); }
public IHttpActionResult PutCarCategory(int id, CarCategory carCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != carCategory.ID) { return(BadRequest()); } _db.Entry(carCategory).State = EntityState.Modified; try { _db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CarCategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public CarCategory Add(CarCategory item) { //Function to add a new car category item to the DB and save var category = Context.CarCategories.Add(item); Context.SaveChanges(); return(category); }
public CarCategory Update(CarCategory item) { //update the car category with new items Categories.RemoveAll(x => x.Category.Equals(item.Category, StringComparison.InvariantCultureIgnoreCase)); Categories.Add(item); return(item); }
public bool?ChangeStatus(int Id) { CarCategory entity = db.CarCategories.Find(Id); entity.Status = !entity.Status; db.SaveChanges(); return(entity.Status); }
public ActionResult DeleteConfirmed(int id) { CarCategory carCategory = db.CarCategories.Find(id); db.CarCategories.Remove(carCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public RentalCar( long idRentalCar, int milageKm, CarCategory carCategory) { IdRentalCar = idRentalCar; MilageKm = milageKm; CarCategory = carCategory; }
public int InsertCarCategory(CarCategory category) { using (var context = new ApplicationDbContext()) { context.CarCategories.Add(category); context.SaveChanges(); return(category.Id); } }
private OwnerCarsStatistic RecordToUniqueOwnerCarStatistic(NpgsqlDataReader dataReader) { OwnerCarsStatistic ownerCarsStatistic = new OwnerCarsStatistic(); ownerCarsStatistic.Category = CarCategory.GetCategoryByDBValue(dataReader.GetString(0)); ownerCarsStatistic.uniqueCarsOwned = dataReader.GetInt32(1); return(ownerCarsStatistic); }
public Task <List <Car> > FindAvailableCars( CarCategory category, DateTime startDate, DateTime endDate, DateTime currentDate) { AssertRentalRangeValid(startDate, endDate, currentDate); return(FindAvailableCarsForRange(startDate, endDate) .Where(car => car.Category == category) .ToListAsync()); }
public JsonResult LoadCarCategoryDetail(int Id) { var dao = new CarCategoryDAO(); CarCategory entity = dao.GetDetailByID(Id); return(Json(new { data = entity }, JsonRequestBehavior.AllowGet)); }
// // GET: /CarCategory/Details/5 public ActionResult Details(int id = 0) { CarCategory carcategory = db.CarCategories.Find(id); if (carcategory == null) { return(HttpNotFound()); } return(View(carcategory)); }
public ActionResult add_car() { var categories_db = db.Categories.ToList(); CarCategory cc = new CarCategory { categories = categories_db }; return(PartialView(cc)); }
public async Task <IActionResult> PutCarCategory(int id, [FromBody] CarCategory carCategory) { if (id != carCategory.Id) { return(BadRequest()); } // _repo.Update(carCategory); return(ApiOk(await _repo.Update(carCategory))); }
public ActionResult Edit([Bind(Include = "ID,Name")] CarCategory carCategory) { if (ModelState.IsValid) { db.Entry(carCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(carCategory)); }
public int CreateEditCarCategory(CarCategory entity, string username) { if (entity.ID == 0) { entity.CreatedBy = username; entity.ModifiedBy = username; entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; db.CarCategories.Add(entity); try { db.SaveChanges(); return(1); } catch (Exception) { return(0); } } if (entity.ID != 0) { CarCategory car = db.CarCategories.Find(entity.ID); car.Name = entity.Name; car.MetaTitle = entity.MetaTitle; car.ParentID = entity.ParentID; car.DisplayOrder = entity.DisplayOrder; car.SeoTitle = entity.SeoTitle; car.ModifiedBy = username; car.ModifiedDate = DateTime.Now; car.MetaKeywords = entity.MetaKeywords; car.MetaDescriptions = entity.MetaDescriptions; car.Status = entity.Status; if (car.ParentID != 0) { IEnumerable <CarCategory> listCar = db.CarCategories.Where(x => x.ParentID == entity.ID); int i = GetDisplayOrder(0, 0, "none") - 1; foreach (var item in listCar) { item.ParentID = 0; item.DisplayOrder = i++; } } try { db.SaveChanges(); return(2); } catch (Exception) { return(0); } } return(0); }
public void UpdateCarCategory(CarCategory category) { using (var context = new ApplicationDbContext()) { if (context.CarCategories.Count(cc => cc.Id == category.Id) > 0) { (context.Entry(category)).State = EntityState.Modified; context.SaveChanges(); } } }
public ActionResult Create([Bind(Include = "ID,Name")] CarCategory carCategory) { if (ModelState.IsValid) { db.CarCategories.Add(carCategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(carCategory)); }
public async Task <IActionResult> Edit(CarCategory carCategoryModel) { if (carCategoryModel.Name == null) { return(BadRequest()); } CarCategory carCategory = carCategoryService.Edit(carCategoryModel); return(Ok(carCategory)); }
public IHttpActionResult GetCarCategory(int id) { CarCategory carCategory = _db.CarCategories.Find(id); if (carCategory == null) { return(NotFound()); } return(Ok(carCategory)); }
public string GetFullCatLocation(CarCategory cat) { if (cat.CatLevel == 1) { return(db.CarCategories.FirstOrDefault(x => x.CatID == cat.CatParentID).CatName + " » " + cat.CatName); } else { return(cat.CatName); } }
protected void BtnCommand_Click(object sender, EventArgs e) { CarCategory loc = new CarCategory(); loc.Name = txtName.Text; loc.Active = chkActive.Checked; int result = DataService.Provider.AddCarCategory(loc); if (result > 0) { Response.Redirect(Util.AdminUrl + "manage-vehicle", true); } }
public int InsertCarCategory(CarCategory category) { using (var connection = new SqlConnection(ConnectionString)) { var insertCommand = new SqlCommand(@"INSERT INTO CarCategories ([Code], [Description]) VALUES (@Code, @Description) SET @Id = SCOPE_IDENTITY()", connection); var codeSqlParam = new SqlParameter { ParameterName = "@code", SqlDbType = SqlDbType.NVarChar, Value = category.Code, }; var descriptionSqlParam = new SqlParameter { ParameterName = "@Description", SqlDbType = SqlDbType.NVarChar, Value = category.Description }; var idSqlParam = new SqlParameter { ParameterName = "@id", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Output }; insertCommand.Parameters.Add(codeSqlParam); insertCommand.Parameters.Add(descriptionSqlParam); insertCommand.Parameters.Add(idSqlParam); connection.Open(); insertCommand.ExecuteScalar(); return ((int)insertCommand.Parameters["@Id"].Value); } }
public void UpdateCarCategory(CarCategory category) { throw new NotImplementedException(); }