public void Remove(int idResidence) { IResidence res = this.GetResidence(idResidence); this._dataContext.cov_Residences.DeleteOnSubmit((cov_Residence)res); this._dataContext.SubmitChanges(); }
static void CalcCrimeForHome(IResidence residence) { int happiness = residence.GetHappiness(); int severity = (crimeHappinessThreshold - happiness); if (severity > 0) { float severityNormalized = (float)severity / (float)crimeHappinessThreshold; Mod.helper.Log("found home with potential crime: " + severityNormalized.ToString()); foreach (Villager resident in residence.GetResidents()) { bool flaggedCriminal = SRand.Range(0f, 1f) < severityNormalized; if (flaggedCriminal) { Mod.helper.Log("trying create criminal"); Criminal bestCriminal = GetBestCriminalForSeverity(severityNormalized); if (bestCriminal) { CreateCriminal(bestCriminal, resident); } } } } }
public IResidence GetHome() { IResidence result = houses[rand.Next(houses.Count)]; while (!result.HavePlace()) { result = houses[rand.Next(houses.Count)]; } return(result); }
public ResidenceController(IResidence residence) { _residence = residence; }
public void Remove(IResidence res) { this._dataContext.cov_Residences.DeleteOnSubmit((cov_Residence)res); this._dataContext.SubmitChanges(); }
public List <PointF> FindPath(Point start, IResidence finish) { return(FindPath(start, finish as IBuilding)); }
public ActionResult Create(ProjetViewData projetData, ResidenceViewData residenceData, TransportViewData transportData) { /* * projetData = new ProjetViewData * { * commentaires = "Projet qui me tien à coeur", * villeArrive = "Paris", * dateDebut = "22/08/09", * dateFin = "25/12/09", * heureDepart = "22h32", * paysArrive = "25", * paysDepart = "77" * }; * residenceData = new ResidenceViewData * { * adresse = "14 rue des longchamps 91650 breux", * maxhotes = "23", * prixres = "32.54", * typeres = "chez moi" * }; * * transportData = new TransportViewData * { * numvol = "B5464", * modetrans = "Avion", * prixtrans = "43.54", * details = null * }; * */ DateTime datedeb, datefin; DateTime?vDateDeb = null, vDateFin = null; int paysarr, paysdep; int maxhotes = -1; double prixres = 0d, prixtrans = 0d; bool incertain; int nbJours = -1; projetData.incertain = (!string.IsNullOrEmpty(projetData.incertain)) ? projetData.incertain : bool.FalseString; incertain = bool.Parse(projetData.incertain); if (!incertain) { if (DateTime.TryParse(projetData.dateDebut, out datedeb) == false) { this.ModelState.AddModelError("dateDebut", "La date de départ est incorecte"); } else if (datedeb.Year >= DateTime.Now.Year + 2) { this.ModelState.AddModelError("dateDebut", "La date de départ doit se situer dans les 2 prochaines années"); } else if (datedeb <= DateTime.Now) { this.ModelState.AddModelError("dateDebut", "La date de départ souhaitée est déjà dépassée"); } if (DateTime.TryParse(projetData.dateFin, out datefin) == false) { this.ModelState.AddModelError("dateFin", "La date de retour prevue est incorecte"); } else if (datefin.Year >= DateTime.Now.Year + 2) { this.ModelState.AddModelError("dateFin", "La date de retour doit se situer dans les 2 prochaines années"); } else if (datefin <= DateTime.Now) { this.ModelState.AddModelError("dateFin", "La date de retour est déjà dépassée"); } else if (datefin < datedeb.AddDays(1)) { this.ModelState.AddModelError("dateFin", "La date de retour doit être au moins 1 jour apres la date de départ"); } vDateDeb = datedeb; vDateFin = datefin; } else { if (!int.TryParse(projetData.nbjours, out nbJours)) { this.ModelState.AddModelError("nbjours", "La duree du voyage est incorrecte"); } else if (nbJours < 1) { this.ModelState.AddModelError("nbjours", "Le voyage doit durer au minimum 1 jour"); } else if (nbJours >= (365 * 2)) { this.ModelState.AddModelError("nbjours", "Le voyage doit durer maximum 2 ans "); } } if (int.TryParse(projetData.paysArrive, out paysarr) == false) { this.ModelState.AddModelError("paysArrive", "Le pays de destination selectionné est incorecte"); } if (int.TryParse(projetData.paysDepart, out paysdep) == false) { this.ModelState.AddModelError("paysDepart", "Le pays de départ selectionné est incorecte"); } if (incertain /*bool.Parse(projetData.incertain) */ && projetData.dateDebut.Trim() != "" && projetData.dateFin.Trim() != "" && int.TryParse(projetData.nbjours, out nbJours)) { this.ModelState.AddModelError("nbjours", "Vous devez spécifier une durée en nombre de jour si vous ne pouvez indiquer de dates précises"); } if (projetData.dateDebut.Trim() != "" && projetData.dateFin.Trim() != "" && incertain == true && !int.TryParse(projetData.nbjours, out nbJours)) { this.ModelState.AddModelError("_FORM", "Vous devez spécifier une durée en nombre de jour ou des dates précises"); } //Convertion des "." en virgule //FIXME: CREERPROJET Plante si plusieurs "." ou "," dans le prixres trans residenceData.prixres = residenceData.prixres.Replace(".", ",").Trim(); transportData.prixtrans = transportData.prixtrans.Replace(".", ",").Trim(); if (residenceData.prixres != "" && double.TryParse(residenceData.prixres, out prixres) == false) { this.ModelState.AddModelError("prixres", "Le prix indiqué est incorrecte"); } if (transportData.prixtrans != "" && double.TryParse(transportData.prixtrans, out prixtrans) == false) { this.ModelState.AddModelError("prixtrans", "Le prix indiqué est incorrecte"); } if (residenceData.typeres.ToUpper() == "CHEZ MOI" || residenceData.typeres.ToUpper() == "AMIS") { residenceData.maxhotes = residenceData.maxhotes.Trim(); if (residenceData.maxhotes != "" && int.TryParse(residenceData.maxhotes, out maxhotes) == false) { this.ModelState.AddModelError("maxhotes", "Nombre d'hotes maximum incorrecte"); } } if (this.ModelState.IsValid) { IProjet proj = Data.ProjetDataAccess.Create(); IResidence res = Data.ResidenceDataAccess.CreateResidence(); ITransport trans = Data.TransportDataAccess.CreateTransport(); proj.DateCreation = DateTime.Now; proj.DateModification = proj.DateCreation; proj.Incertain = incertain; if (!incertain) { proj.DateDebut = vDateDeb; proj.DateFin = vDateFin; proj.NbJours = (int)proj.GetDuree().timeSpan.TotalDays; } else { proj.DateDebut = null; proj.DateFin = null; proj.NbJours = nbJours; } proj.IdPaysDepart = paysdep; proj.IdPaysArrive = paysarr; proj.Commentaires = projetData.commentaires.Trim(); proj.OwnerUserId = this.CurrentUser.UserId; proj.VilleArrive = projetData.villeArrive.Trim().ToTitleCase(); if (GotResidence(residenceData.typeres)) { res.Prix = prixres;//double.Parse(residenceData.prixres.Trim()); res.Type = residenceData.typeres.Trim().ToUpper(); res.Adresse = residenceData.adresse.Trim(); if (res.Type == "CHEZ MOI" || res.Type == "AMIS") { res.MaxHotes = maxhotes; } proj.Residence = res; } if (GotTransport(transportData.modetrans)) { trans.ModeTransport = transportData.modetrans.Trim().ToUpper(); //TODO: ajpouter details du transport dans la vue. Modale?? trans.Details = transportData.details ?? ""; trans.PrixAR = prixtrans; if (trans.ModeTransport == "AVION") { trans.Compagnie = transportData.compagnie; //?? null; trans.NumVol = transportData.numvol; //?? null; } proj.TransportsEntitySet.Add((cov_Transport)trans); } try { Data.ProjetDataAccess.InsertProjet(proj); } catch (Exception ex) { string errmsg = "Votre projet de voyage n'a pas pu être enregistré."; //"Une erreur est survenue lors de l'envoi de l'email de confirmation. Si le probleme persiste veillez contacter " + Configuration.SiteAdminEmail + "."; //TODO:REDIRECT TO ACTION return(Error(errmsg)); } return(RedirectToAction("CreateSuccess", new { IdProjet = proj.IdProjet })); } return(View()); }
private IProjet UpdateProjet(CreateProjetViewData newDataProjet) { // DateTime datedeb, datefin; DateTime?vDateDeb = null, vDateFin = null; int maxhotes = newDataProjet.maxhotes ?? -1; double prixres = 0d, prixtrans = 0d; bool incertain; int nbJours = -1; // newDataProjet.incertain = (!string.IsNullOrEmpty(newDataProjet.incertain)) ? newDataProjet.incertain : bool.FalseString; incertain = newDataProjet.incertain; if (newDataProjet.projetid == null) { throw new Exception("Le projet à éditer est introuvable"); } int projetId = newDataProjet.projetid.Value; IProjet proj = Data.ProjetDataAccess.GetProjet(projetId); if (proj == null) { throw new Exception("Le projet à éditer est introuvable"); } if (proj.OwnerUserId != this.CurrentUserId) { throw new Exception(this.CurrentUserId.ToString() + " n'est pas le propriétaire de ce projet et ne peut pas le modifier"); } IResidence res = null; ITransport trans = null; if (GotResidence(newDataProjet.typeres)) { res = Data.ResidenceDataAccess.CreateResidence(); } if (GotTransport(newDataProjet.modetrans)) { trans = Data.TransportDataAccess.CreateTransport(); } //using(TransactionScope transx = new TransactionScope()) //{ proj.DateModification = DateTime.Now; proj.Incertain = incertain; if (!incertain) { vDateDeb = newDataProjet.dateDebut; vDateFin = newDataProjet.dateFin; proj.DateDebut = vDateDeb; proj.DateFin = vDateFin; proj.NbJours = (int)proj.GetDuree().timeSpan.TotalDays; } else { // nbJours = proj.DateDebut = null; proj.DateFin = null; proj.NbJours = newDataProjet.nbjours.Value; } proj.Commentaires = newDataProjet.commentaires.Trim(); // proj.OwnerUserId = this.CurrentUser.UserId; //remove residence if (res == null) { if (proj.Residence != null) { // int resId = proj.Residence.Id; // proj.Residence = null; // Data.CovCakeDataContext.SubmitChanges(); // Data.ProjetDataAccess.SubmitChanges(); // Data.ResidenceDataAccess.Remove(resId); Data.ResidenceDataAccess.Remove(proj.Residence.Id); } } else { res.Prix = newDataProjet.prixres ?? 0;//double.Parse(residenceData.prixres.Trim()); res.Type = newDataProjet.typeres.Trim().ToUpper(); res.Adresse = newDataProjet.adresse.Trim(); if (res.Type == "CHEZ MOI" || res.Type == "AMIS") { res.MaxHotes = maxhotes; } proj.Residence = res; } if (trans == null) { // Data.TransportDataAccess.Remove(proj.Transports.FirstOrDefault().IdTransport); proj.TransportsEntitySet.Clear(); } else { proj.TransportsEntitySet.Clear(); trans.ModeTransport = newDataProjet.modetrans.Trim().ToUpper(); trans.Details = newDataProjet.details ?? ""; trans.PrixAR = newDataProjet.prixtrans ?? 0; //prixtrans; if (trans.ModeTransport == "AVION") // || trans.ModeTransport.Trim() == " { trans.Compagnie = newDataProjet.compagnie; //?? null; trans.NumVol = newDataProjet.numvol; //?? null; } proj.TransportsEntitySet.Add((cov_Transport)trans); } // Data.ProjetDataAccess.SubmitChanges(); // transx.Complete(); return(proj); // } }