Exemplo n.º 1
0
        public ActionResult Edit(int projetId)
        {
            IProjet proj = Data.ProjetDataAccess.GetProjet(projetId);

            if (proj == null)
            {
                return(RedirectToAction("MonCompte", "User"));
            }

            string /*transPrix = "0", resPrix = "0", resMaxHote = "0",*/ resType = "", modeTrans = "";
            double?  transPrix = null, resPrix = null;
            int?     resMaxHote = null;
            DateTime?dateDeb, dateFi;

            dateDeb = proj.DateDebut;
            dateFi  = proj.DateFin;// != null) ? proj.DateFin.Value.ToShortDateString() : "";

            if (proj.Residence != null)
            {
                resPrix = proj.Residence.Prix;
                if (proj.Residence.MaxHotes > 1)
                {
                    resMaxHote = proj.Residence.MaxHotes;
                }
                resType = proj.Residence.Type;
            }


            if (proj.Transports.Count() > 0)
            {
                ITransport trans = proj.Transports.First();
                modeTrans = trans.ModeTransport;
                transPrix = trans.PrixAR;;
            }
            int?nbjours = proj.NbJours;
            CreateProjetViewData projetViewData = new CreateProjetViewData()
            {
                adresse      = (proj.Residence != null) ? proj.Residence.Adresse : "",
                commentaires = proj.Commentaires,
                dateDebut    = dateDeb,
                dateFin      = dateFi,
                nbjours      = (proj.NbJours > 0) ? nbjours : null,
                villeArrive  = proj.VilleArrive,
                incertain    = bool.Parse(proj.Incertain.ToString().ToLower()),
                modetrans    = modeTrans,
                prixtrans    = transPrix,
                prixres      = resPrix,//(prresPrix > 0) ? proj.NbJours.ToString() : "",,
                typeres      = resType,
                maxhotes     = resMaxHote,

                Projet = proj
            };

            ViewData["title"] = "Editer mon voyage vers " + proj.PaysArrive.LibellePays;
            return(View(projetViewData));
        }
Exemplo n.º 2
0
        public ActionResult Edit(CreateProjetViewData newDataProjet)
        {
            /*
             * newDataProjet = new CreateProjetViewData()
             * {
             *  nbjours = "45",
             *  incertain = "true",
             *  details = "fhdzhenbdk",
             * // typeres = "HOTEL",
             *  typeres = "FAKE",
             *  prixres = "45,76",
             *
             *  modetrans = "FAKE",
             *  //modetrans = "TRAIN",
             *  adresse = "",
             *  prixtrans = "5",
             *  commentaires = "sale nbatar",
             *  projetid = "15"
             *
             * }; //
             */
            IProjet proj = UpdateProjet(newDataProjet);

            try
            {
                Data.ProjetDataAccess.SubmitChanges();
                SendProjetEditNotification(proj);
            }
            catch (ChangeConflictException lnkEx)
            {
            }
            catch (Exception ex)
            {
                ViewData["ErrorMsg"] = "Votre projet de voyage n'a pas pu être modifié."; //"Une erreur est survenue lors de l'envoi de l'email de confirmation. Si le probleme persiste veillez contacter " + Configuration.SiteAdminEmail + ".";
                return(View("Error"));
            }

            return(RedirectToRoute(CovCake.Routes.MONCOMPTE));//."MonCompte","User");// View("CreateSuccess");
        }
Exemplo n.º 3
0
        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);
            // }
        }