public void Save(Amenity amenity) { if (amenity.IsValid()) { AmenityRepo.Save(amenity); } }
public ActionResult Edit(Amenity amenity) { if (ModelState.IsValid) { db.Entry(amenity).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(amenity); }
public bool UpdateAmenity(string landlordReference, string submittedPropertyReference, string amenityReference, Amenity amenity) { Check.If(landlordReference).IsNotNullOrEmpty(); Check.If(submittedPropertyReference).IsNotNullOrEmpty(); Check.If(amenityReference).IsNotNullOrEmpty(); Check.If(amenity).IsNotNull(); return _amenityRepository.UpdateAmenity(landlordReference, submittedPropertyReference, amenityReference, amenity); }
public string CreateAmenity(string landlordReference, string submittedPropertyReference, Amenity amenity) { Check.If(landlordReference).IsNotNullOrEmpty(); Check.If(submittedPropertyReference).IsNotNullOrEmpty(); Check.If(amenity).IsNotNull(); var result = _amenityRepository.CreateAmenity(landlordReference, submittedPropertyReference, amenity.CreateReference(_referenceGenerator)); return result ? amenity.AmenityReference : null; }
public ActionResult Create(Amenity amenity) { // If we don't track the entity, then a new record will be created for org! db.Organizations.Attach(SiteContext.CurrentOrganization); amenity.Organization = SiteContext.CurrentOrganization; if (ModelState.IsValid) { db.Amenities.Add(amenity); db.SaveChanges(); return RedirectToAction("Index"); } return View(amenity); }
public ActionResult Index(FormCollection form, Amenity amenity) { //re-writing the drop down list so it's available in post. IEnumerable <SelectListItem> items = db.Amenities.Select(l => new SelectListItem { Value = l.Id.ToString(), Text = l.Amenity_Name }); ViewBag.Amenity = items; //collecting the value of the form so we can get the building it the service is located in, closest parking and entrance. //converting our string value into an int so we can use it to grab our amenity/service. string amenity_id = form["Amenity"]; int a_id = Convert.ToInt32(amenity_id); amenity = db.Amenities.Where(a => a.Id == a_id).FirstOrDefault(); ViewBag.AmenityName = amenity.Amenity_Name; //now lets get the building. Building building = new Building(); building = db.Buildings.Where(b => b.Id == amenity.Building_id).FirstOrDefault(); ViewBag.Building = building.Building_Name; //now let's get the parking List <ParkingLot> parking = db.ParkingLots.Where(p => p.Building_id == amenity.Building_id).ToList(); foreach (var item in parking) { ViewBag.Parking += "<li>" + item.Lot_Name + "</li>"; } //now let's get the entrances List <Entrance> entrance = db.Entrances.Where(e => e.Building_id == amenity.Building_id).ToList(); foreach (var item in entrance) { ViewBag.Entrance += "<li>" + item.Entrance_Name + "</li>"; } return(View(amenity)); }
public bool CreateAmenity(string landlordReference, string submittedPropertyReference, Amenity amenity) { var landlord = _propertiesContext.Landlords.Active() .Include(l => l.SubmittedProperties) .Include(l => l.SubmittedProperties.Select(s => s.Amenities)) .FirstOrDefault(l => l.LandlordReference == landlordReference); var property = landlord?.SubmittedProperties.Active() .FirstOrDefault(s => s.SubmittedPropertyReference == submittedPropertyReference); if (property.IsNull()) return false; property.Amenities.Add(amenity); return _propertiesContext.SaveChanges() > 0; }
public void GetValuesShouldReturnSetValues() { // Arrange string jobTitle = "JobTitle"; string employer = "Employer"; string city = "City"; string state = "State"; string status = "Status"; decimal minimumSalary = decimal.MinValue; decimal maximumSalary = decimal.MaxValue; DateTime dateSubmitted = DateTime.MinValue; DateTime dateLastUpdated = DateTime.MaxValue; Amenity amenity = new Amenity(); TechnologyStack technologyStack = new TechnologyStack(); CreateJobRequest sut = new CreateJobRequest(); // Act sut.JobTitle = jobTitle; sut.Employer = employer; sut.City = city; sut.State = state; sut.Status = status; sut.MinimumSalary = minimumSalary; sut.MaximumSalary = maximumSalary; sut.DateSubmitted = dateSubmitted; sut.DateLastUpdated = dateLastUpdated; sut.Amenities = amenity; sut.TechnologyStack = technologyStack; // Assert Assert.Equal(jobTitle, sut.JobTitle); Assert.Equal(employer, sut.Employer); Assert.Equal(city, sut.City); Assert.Equal(state, sut.State); Assert.Equal(status, sut.Status); Assert.Equal(minimumSalary, sut.MinimumSalary); Assert.Equal(maximumSalary, sut.MaximumSalary); Assert.Equal(dateSubmitted, sut.DateSubmitted); Assert.Equal(dateLastUpdated, sut.DateLastUpdated); Assert.Equal(amenity, sut.Amenities); Assert.Equal(technologyStack, sut.TechnologyStack); }
public Object CrearAmenity([FromBody] Amenity amenity) { try { var logueado = HttpContext.Session.Authenticated(); var id_barrio = logueado.IdBarrio.Value; amenity.IdBarrio = id_barrio; db.Amenity.Add(amenity); db.SaveChanges(); return(new { error = false, data = amenity }); } catch (Exception err) { return(new { error = true, data = err.Message }); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { if (txtAmenityName.Text.Trim() == "") { MessageBox.Show("Amenity name was required!", "Message", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (txtPrice.Text.Trim() == "") { MessageBox.Show("Amenity price was required!", "Message", MessageBoxButton.OK, MessageBoxImage.Error); return; } else { try { double.Parse(txtPrice.Text); } catch (Exception) { MessageBox.Show("Amenity price must be digits", "Message", MessageBoxButton.OK, MessageBoxImage.Error); return; } } if (Db.Context.Amenities.ToList().Where(t => t.Service == txtAmenityName.Text).FirstOrDefault() != null) { MessageBox.Show("This amenity was exitst!", "Message", MessageBoxButton.OK, MessageBoxImage.Error); return; } Amenity amenity = new Amenity() { Service = txtAmenityName.Text, Price = decimal.Parse(txtPrice.Text) }; Db.Context.Amenities.Add(amenity); Db.Context.SaveChanges(); ManageWindow.LoadAmenities(); MessageBox.Show("Add amenity successful!", "Message", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); }
public IActionResult DeleteRoomAmenity([FromBody]Amenity data) { if (isEmployee()) { if (deleteRoomAmenity(data.Aid)) { return Json("Success"); } else { return Json("Error: Could not delete the amenity"); } } else { return RedirectToAction("AccessDenied", "Account"); } }
public ActionResult AmenityEdit(Amenity amen) { string[] err = new string[] { }; if (amen.Validate(out err)) { status = UResidence.AmenityController.Update(amen); if (status == true) { ViewBag.UpdateMessage = status; return(RedirectToAction("AmenityView")); } } else { ViewBag.ErrorMessages = FixMessages(err); } return(View(amen)); }
public IActionResult AddRoomAmenity([FromBody]Amenity data) { if (isEmployee()) { int insertResult = addRoomAmenity(data.Rid, data.Amenity1); if (insertResult > 0) { return Json(insertResult); } else { return Json("Error: Could not add the amenity"); } } else { return RedirectToAction("AccessDenied", "Account"); } }
public async void CanSaveAmenityToDB() { DbContextOptions <HotelDbContext> options = new DbContextOptionsBuilder <HotelDbContext>().UseInMemoryDatabase("DbSaveAmenity").Options; using (HotelDbContext context = new HotelDbContext(options)) { // Arrange Amenity amenity = new Amenity(); amenity.Name = "Ice Box"; context.Amenities.Add(amenity); context.SaveChanges(); // Act var amenityName = await context.Amenities.FirstOrDefaultAsync(); // Assert Assert.Equal("Ice Box", amenityName.Name); } }
public async Task <bool> UpdateAmenity(Amenity amenity) { _context.Entry(amenity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!await AmenityExistsAsync((int)amenity.Id)) { return(false); } else { throw; } } return(true); }
public static List <Amenity> ToEntityList(List <CheckBoxVm> defaultAmenities, List <AmenityVm> amenities) { int id; List <Amenity> result = new List <Amenity>(); if (amenities != null) { result = ( from m in amenities where !string.IsNullOrWhiteSpace(m.Name) select m.ToEntity()).ToList <Amenity>(); foreach (Amenity amenity in result) { if (amenity.ClassId.HasValue) { continue; } amenity.ClassId = new int?(0); } } if (defaultAmenities != null) { foreach (CheckBoxVm defaultAmenity in from m in defaultAmenities where m.IsChecked select m) { if (!int.TryParse(defaultAmenity.Value, out id)) { continue; } Amenity amenity = new Amenity() { ClassId = new int?(id), Name = defaultAmenity.Text }; result.Add(amenity); } } return(result); }
public async void CreateAmenityDB() { DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>() .UseInMemoryDatabase("CreateAmenity") .Options; using (AsyncInnDbContext context = new AsyncInnDbContext(options)) { //create amenity and assign values Amenity a = new Amenity(); a.Name = "Air Conditioning"; context.Amenity.Add(a); context.SaveChanges(); var amenity = await context.Amenity.FirstOrDefaultAsync(x => x.Name == a.Name); // assert db entry Assert.Equal(amenity.Name, a.Name); } }
public List <Amenity> Get() { List <Amenity> list = null; DataProvider.ExecuteCmd(GetConnection, "dbo.Amenities_Select" , inputParamMapper : null , map : delegate(IDataReader reader, short set) { Amenity p = MapAmenities(reader); if (list == null) { list = new List <Amenity>(); } list.Add(p); } ); return(list); }
public IActionResult PutAmenity([FromRoute] int id, [FromBody] Amenity amenity) { if (amenity == null) { return(BadRequest("Employee is null.")); } Amenity amenitytoupdate = _context.Amenity .FirstOrDefault(e => e.Id == id); if (amenitytoupdate == null) { return(NotFound("The Employee record couldn't be found.")); } amenitytoupdate.Label = amenity.Label; amenitytoupdate.Amenityorder = amenity.Amenityorder; amenitytoupdate.IsActive = amenity.IsActive; _context.SaveChanges(); return(NoContent()); }
private void btnEditAmenity_Click(object sender, RoutedEventArgs e) { if (currentAmenity != null) { try { EditAmenityWindow wEditAmenity = new EditAmenityWindow(); wEditAmenity.Amenity = currentAmenity; wEditAmenity.ManageWindow = this; wEditAmenity.ShowDialog(); currentAmenity = null; } catch (Exception) { } } else { MessageBox.Show("Please choose a amenity!", "Message", MessageBoxButton.OK, MessageBoxImage.Error); } }
public async void DeleteRoomAmenityDB() { DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>() .UseInMemoryDatabase("DeleteRoomAmenity") .Options; using (AsyncInnDbContext context = new AsyncInnDbContext(options)) { //Acreate room, create amenity, create //room amenity Amenity a = new Amenity(); a.Name = "Air Conditioning"; Room r = new Room(); r.Name = "Mii amo"; context.Add(a); context.Add(r); context.SaveChanges(); var amenity = context.Amenity.FirstOrDefaultAsync(x => x.Name == a.Name); var room = context.Rooms.FirstOrDefaultAsync(x => x.Name == r.Name); RoomAmenity ra = new RoomAmenity(); ra.AmenitiesID = amenity.Id; ra.RoomID = room.Id; context.RoomAmenity.Add(ra); context.SaveChanges(); //Act var roomamenity = await context.RoomAmenity.FirstOrDefaultAsync(x => x.AmenitiesID == ra.AmenitiesID); context.RoomAmenity.Remove(roomamenity); context.SaveChanges(); var deletedRA = await context.RoomAmenity.FirstOrDefaultAsync(x => x.AmenitiesID == ra.AmenitiesID); //assert db entry Assert.Null(deletedRA); } }
public static List <Amenity> GetAmenities(this SqlDataReader reader, List <Amenity> dbDefaultAmenities) { int? classId; List <Amenity> amenities = new List <Amenity>(); Dictionary <int, string> defaultAmenities = new Dictionary <int, string>(); foreach (Amenity item in dbDefaultAmenities) { classId = item.ClassId; defaultAmenities.Add(classId.Value, item.Name); } while (reader.Read()) { bool?isActive = reader.GetNullableValue <bool>("IsActive"); if (!isActive.HasValue || !isActive.Value) { continue; } Amenity item = new Amenity() { Id = reader.GetNullableValue <long>("AmenityId"), CommunityId = reader.GetNullableValue <long>("CommunityId"), ClassId = reader.GetNullableValue <int>("AmenityTypeId") }; string description = reader["AdditionalDescription"].ToString(); if (!string.IsNullOrEmpty(description)) { item.Name = description; } else if (item.ClassId.HasValue && defaultAmenities.ContainsKey(item.ClassId.Value)) { classId = item.ClassId; item.Name = defaultAmenities[classId.Value]; } amenities.Add(item); } return(amenities); }
public bool CreateAmenity(AmenityCreate model) { var newAmenity = new Amenity { Name = model.Name, Description = model.Description, CreatedAt = DateTime.Now }; try { using (var ctx = new ApplicationDbContext()) { ctx.Amenities.Add(newAmenity); return(ctx.SaveChanges() == 1); } } catch (Exception e) { SentrySdk.CaptureException(e); return(false); } }
/// <summary> /// Delete - allows us to delete an amenity /// </summary> /// <param name="Id">the unique identifier of the amenity we want to delete</param> /// <returns>the task complete - the amenity was deleted</returns> public async Task Delete(int Id) { // THIS DOES NOT WORK //AmenityDTO amenityDTO = await GetAmenity(Id); //Amenity amenity = new Amenity() //{ // Id = amenityDTO.Id, // Name = amenityDTO.Name, //}; Amenity amenity = await _context.Amenities.FindAsync(Id); if (amenity == null) { return; } else { _context.Entry(amenity).State = EntityState.Deleted; await _context.SaveChangesAsync(); } }
public Amenity AddAmenity(string amenityName) { var newAmenity = new Amenity { AmenityName = amenityName }; using (var dbContextTransaction = db.Database.BeginTransaction()) { try { newAmenity = db.Amenities.Add(newAmenity); db.SaveChanges(); dbContextTransaction.Commit(); return(newAmenity); } catch (Exception) { dbContextTransaction.Rollback(); return(null); } } }
public async void CanDeleteAmenityFromDB() { DbContextOptions <HotelDbContext> options = new DbContextOptionsBuilder <HotelDbContext>().UseInMemoryDatabase("DbDeleteAmenity").Options; using (HotelDbContext context = new HotelDbContext(options)) { // Arrange Amenity amenity = new Amenity(); amenity.Name = "Ice Box"; context.Amenities.Add(amenity); context.SaveChanges(); // Act context.Amenities.Remove(amenity); context.SaveChanges(); var amenityName = await context.Amenities.FirstOrDefaultAsync(); // Assert Assert.False(context.Amenities.Any()); } }
public async void CanUpdateRoomAmenityInDB() { DbContextOptions <HotelDbContext> options = new DbContextOptionsBuilder <HotelDbContext>().UseInMemoryDatabase("DbUpdateRoomAmenity").Options; using (HotelDbContext context = new HotelDbContext(options)) { Room room = new Room(); room.Name = "Cove"; room.Layout = Layout.OneBedroom; context.Rooms.Add(room); Amenity amenityOne = new Amenity(); amenityOne.Name = "Mini Bar"; context.Amenities.Add(amenityOne); Amenity amenityTwo = new Amenity(); amenityTwo.Name = "Cigars"; context.Amenities.Add(amenityTwo); // Arrange RoomAmenity roomAmenity = new RoomAmenity(); roomAmenity.Room = room; roomAmenity.Amenity = amenityOne; // Act roomAmenity.Amenity = amenityTwo; context.RoomAmenities.Update(roomAmenity); context.SaveChanges(); var nameOfRoomAmenity = await context.RoomAmenities.FirstOrDefaultAsync(); // Assert Assert.Equal(amenityTwo, nameOfRoomAmenity.Amenity); } }
private void btnDeleteAmenity_Click(object sender, RoutedEventArgs e) { if (currentAmenity != null) { if (currentAmenity.AmenitiesTickets.Count == 0) { if (MessageBox.Show("Do you want to delete this amenity?", "Message", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK) { Db.Context.Amenities.Remove(currentAmenity); Db.Context.SaveChanges(); LoadAmenities(); currentAmenity = null; } } else { MessageBox.Show("This amenity can not be deleted because it was purchased", "Message", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Please choose a amenity!", "Message", MessageBoxButton.OK, MessageBoxImage.Error); } }
public async Task <IActionResult> Create([Bind("AmenityId,Type")] Amenity amenity) { ModelState.Remove("User"); if (ModelState.IsValid) { amenity.User = await _userManager.GetUserAsync(HttpContext.User); var user = await GetCurrentUserAsync(); var isDuplicate = await _context.Amenities .SingleOrDefaultAsync(a => a.User == user && a.Type == amenity.Type); if (isDuplicate != null) { ViewData["Message"] = "You Have Already Added This Amenity."; return(View(amenity)); } _context.Add(amenity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(amenity)); }
public JsonResult Action(Amenity model) { JsonResult json = new JsonResult(); var result = false; if (model.Id > 0) { result = AmenitiesServices.Instance.Edit(model); } else { result = AmenitiesServices.Instance.Save(model); } if (result) { json.Data = new { Success = true }; } else { json.Data = new { Success = false, Message = "Unable To Add Accomodation Type" }; } return(json); }
public async Task <ActionResult <Amenity> > PostAmenity(Amenity amenity) { await _amenity.Create(amenity); return(CreatedAtAction("GetHotel", new { id = amenity.Id }, amenity)); }
public void Delete(Amenity amenity) { AmenityRepo.Remove(amenity); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["ReservationId"] == null) { Response.Redirect("~/UnableAccess.aspx"); } DataView dvxxx = (DataView)Validates.Select(DataSourceSelectArguments.Empty); if ((int)dvxxx.Table.Rows[0][0] != 1) { Response.Redirect("~/UnableAccess.aspx"); } DataView dv = (DataView)ClientIdSelect.Select(DataSourceSelectArguments.Empty); int cid = (int)dv.Table.Rows[0][0]; ClientID.Text = cid.ToString(); int tagg = (int)dv.Table.Rows[0][1]; Label8.Text = "Note: Once you Confirm your Bill it is subjected to create a Contract. You are not allowed to change your amenities and facilities reservation."; if (tagg >= 3) { Button1.Visible = false; Button2.Visible = false; Label8.Visible = false; } DataView dv1 = (DataView)ExpensesSelect.Select(DataSourceSelectArguments.Empty); if (dv1.Table.Rows[0][0] is DBNull) { oe = 0; } else { oe = (Double)dv1.Table.Rows[0][0]; } if (dv1.Table.Rows[0][1] is DBNull) { pb = 0; } else { pb = (Double)dv1.Table.Rows[0][1]; } vr = (Double)dv1.Table.Rows[0][2]; Label1.Text = vr.ToString("n2"); Label5.Text = oe.ToString("n2"); Label6.Text = pb.ToString("n2"); DataView dv2 = (DataView)Amenity.Select(DataSourceSelectArguments.Empty); DataView dv3 = (DataView)Facility.Select(DataSourceSelectArguments.Empty); DataView dv4 = (DataView)Misc.Select(DataSourceSelectArguments.Empty); if (dv2.Table.Rows[0][0] is DBNull) { amntyex = 0; } else { amntyex = (Double)dv2.Table.Rows[0][0]; } if (dv3.Table.Rows[0][0] is DBNull) { facex = 0; } else { facex = (Double)dv3.Table.Rows[0][0]; } if (dv4.Table.Rows[0][0] is DBNull) { miscex = 0; } else { miscex = (Double)dv4.Table.Rows[0][0]; } Label2.Text = amntyex.ToString("n2"); Label3.Text = facex.ToString("n2"); Label4.Text = miscex.ToString("n2"); total = oe + pb + vr + amntyex + facex + miscex; Label7.Text = total.ToString("n2"); LinkButton1.Attributes.Add("onclick", "window.open('../bill.aspx?ReservationId=" + Request.QueryString["ReservationId"] + "', 'newwindow','menubar=1,resizable=1,width=700,height=900');return false;"); }
protected void btnSubmitAmenity_Click(object sender, EventArgs e) { // imput validation Boolean Amenity = UtilityClass.isValidText(txtAmenity, lblAmenityMessage, "*", "Insert leters or digits!"); Boolean Type = UtilityClass.isValidText(ddlType, lblTypeMessage, "*"); // if input is valid then create new amenity object if (Amenity && Type) { Amenity newBee = new Amenity(); newBee.amenity = txtAmenity.Text.Trim(); newBee.type = ddlType.Text.Trim(); // check if the new amenity is in the list if (Amenities.Exists((t) => t.myEquals(newBee))) { lblAmenityMessage.Text = "amenity Exist in the list!"; return; }// end if this._amenity.Add(newBee); lblACreated.Text = "Amenity succesfully created!"; // Sort the amenity list this._amenity = Amenities.OrderBy((a) => a.amenity).ToList(); //overwrite xml file UtilityClass.AmenitySerializeToXML(_amenity); // refresh the grild view GridView1.DataSourceID = null; GridView1.DataSource = this._amenity; GridView1.DataBind(); }// end if(amenity && type) }
public bool UpdateAmenity(string landlordReference, string submittedPropertyReference, string amenityReference, Amenity amenity) { var landlord = _propertiesContext.Landlords.Active() .Include(l => l.SubmittedProperties) .Include(l => l.SubmittedProperties.Select(s => s.Amenities)) .FirstOrDefault(l => l.LandlordReference == landlordReference); var property = landlord?.SubmittedProperties.Active() .FirstOrDefault(s => s.SubmittedPropertyReference == submittedPropertyReference); var existingAmenity = property?.Amenities.FirstOrDefault(f => f.AmenityReference == amenityReference); if (existingAmenity.IsNull()) return false; var isDirty = _amenityMapper.Map(amenity, existingAmenity); return !isDirty || _propertiesContext.SaveChanges() > 0; }
/// <summary> /// Updates a specific Amenity /// </summary> /// <param name="amenity">Unique Amenity identifier</param> /// <returns>Task of completion</returns> public async Task Update(Amenity amenity) { _context.Entry(amenity).State = EntityState.Modified; await _context.SaveChangesAsync(); }
public EditHotelAmenityItem(Amenity amenity, bool isSelected) { Id = amenity.Id; Name = amenity.Name; IsSelected = isSelected; }
public async Task CreateAsync(Amenity amenity) { _context.Amenities.Add(amenity); await _context.SaveChangesAsync(); }
public async Task <ActionResult <Amenity> > PostAmenity(Amenity amenity) { await repository.CreateAsync(amenity); return(CreatedAtAction("GetAmenity", new { id = amenity.Id }, amenity)); }
public AmenityVm(Amenity amenity) { this.Id = amenity.Id; this.ClassId = amenity.ClassId; this.Name = amenity.Name; }