public bool CreateFeature(FeatureCreate model) { var entity = new Feature() { UserID = _userId, PropertyID = new ApplicationDbContext().Properties.Max(id => id.PropertyID), DistanceFromPopulace = model.DistanceFromPopulace, RoadAccess = model.RoadAccess, CityWater = model.CityWater, CityElectric = model.CityElectric, CitySewer = model.CitySewer, Internet = model.Internet, AlternateWater = model.AlternateWater, AlternateElectric = model.AlternateElectric, AlternateSewage = model.AlternateSewage, BodyOfWater = model.BodyOfWater, NearbyBodyOfWater = model.NearbyBodyOfWater }; using (var ctx = new ApplicationDbContext()) { ctx.Features.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(FeatureCreate feat) { if (!ModelState.IsValid) { return(View(feat)); } var service = CreateFeatService(); if (service.CreateFeature(feat)) { TempData["SaveResult"] = "Feature Created"; return(RedirectToAction("Index")); } return(View(feat)); }
//create public bool CreateFeature(FeatureCreate newFeature) { using (var ctx = new ApplicationDbContext()) { var feature = new Feature { OwnerID = _userId, GameType = newFeature.GameType, RacePointCost = newFeature.RacePointCost, FeatureName = newFeature.FeatureName, Description = newFeature.Description, Benefits = newFeature.Benefits, Special = newFeature.Special, RaceIDPrerequisites = new List <FRacePrerequisites>(), //ClassIDPrerequisites, FeatureIDPrerequisites = new List <FFeatPrerequisites>(), StatPrerequisite = String.Join("|", newFeature.StatPrerequisite.Select(s => s.Key + " " + s.Value).ToArray()), LvlPrerequisite = newFeature.LvlPrerequisite, StrengthModifier = newFeature.StrengthModifier, DexterityModifier = newFeature.DexterityModifier, ConstitutionModifier = newFeature.ConstitutionModifier, IntelligenceModifier = newFeature.IntelligenceModifier, WisdomModifier = newFeature.WisdomModifier, CharismaModifier = newFeature.CharismaModifier, IsDeactivated = false, DateOfCreation = DateTimeOffset.UtcNow }; if (newFeature.RaceIdPrerequisite != null) { newFeature.RaceIdPrerequisite.ForEach(e => feature.RaceIDPrerequisites.Add(new FRacePrerequisites { RaceID = e })); } if (newFeature.FeatureIdPrerequisite != null) { newFeature.FeatureIdPrerequisite.ForEach(e => feature.FeatureIDPrerequisites.Add(new FFeatPrerequisites { FeatureID = e })); } ctx.Features.Add(feature); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(FeatureCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateFeatureService(); var rservice = CreateRatingService(); if (service.CreateFeature(model)) { // at the time a feature is created, automatically generates a rating for the property rservice.CreateRating(new RatingCreate { PropertyID = new ApplicationDbContext().Properties.Max(x => x.PropertyID), FeatureID = new ApplicationDbContext().Features.Max(x => x.FeatureID) }); return(RedirectToAction("Index", "Property")); } ; return(View(model)); }