public bool addPriceCategory(PriceCategory priceCategory) { if (!this.personCategories.Contains(priceCategory.personCategory) || !this.tripTypes.Contains(priceCategory.tripType) || !this.routes.Contains(priceCategory.route)) { return(false); } if (this.priceCategories.Contains(priceCategory)) { return(false); } DAL.PriceCategory entity = db.PriceCategory.Where(v => v.id == priceCategory.id).FirstOrDefault(); if (entity == null && (entity = priceCategory.saveInDB()) == null) { return(false); } //entity.boatToursManagerId = this.id; db.SaveChanges(); this.priceCategories.Add(priceCategory); return(true); }
public PriceCategory(DAL.PriceCategory priceCategory) { this.id = priceCategory.id; this.name = priceCategory.name; this.tripType = new TripType(priceCategory.TripType); this.personCategory = new PersonCategory(priceCategory.PersonCategory); this.price = priceCategory.price; //this.route = new Route(priceCategory.Route); // remove comment and solve this }
public bool removePriceCategory(PriceCategory priceCategory) { DAL.PriceCategory entity = db.PriceCategory.Where(v => v.id == priceCategory.id).FirstOrDefault(); if (entity == null) { return(false); } //entity.boatToursManagerId = null; db.SaveChanges(); return(this.priceCategories.Remove(priceCategory)); }
public DAL.PriceCategory saveInDB() { DAL.PriceCategory entity = null; if (this.tripType.id == 0 || this.personCategory.id == 0 || this.route.id == 0) { return(null); } // Create, if not existant if (this.id == 0) { entity = MainClass.Instance.db.PriceCategory.Add(new DAL.PriceCategory() { name = this.name, price = this.price, routeId = this.route.id, tripTypeId = this.tripType.id, personCategoryId = this.personCategory.id }); MainClass.Instance.db.SaveChanges(); this.id = entity.id; } else { entity = MainClass.Instance.db.PriceCategory.Where(v => v.id == this.id).FirstOrDefault(); if (entity == null) { return(null); } entity.name = this.name; entity.price = this.price; entity.routeId = this.route.id; entity.tripTypeId = this.tripType.id; entity.personCategoryId = this.personCategory.id; MainClass.Instance.db.SaveChanges(); } return(entity); }