Exemple #1
0
        public async Task <ActionResult> Apply([Bind(Include = "ID,Texte,Title")] Candidature candidature, int Id)
        {
            if (ModelState.IsValid)
            {
                string id = User.Identity.GetUserId();
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                var user = await UserManager.FindByIdAsync(id);

                if (user == null)
                {
                    return(HttpNotFound());
                }
                string          emailAddress = user.Email;
                ServiceProvider sp           = new ServiceProvider();
                sp = db.ServiceProviders.Where(x => x.Email == emailAddress).FirstOrDefault();
                if (sp == null)
                {
                    return(Content("although you have access to service Provider Space , but you are not registered as Service Provider in Our dtabse , Please contact our Platform administrators for a quick Fix , Thanks!"));
                }
                sp.Candidatures.Add(candidature);
                Mission mis = db.Missions.Where(x => x.ID == Id).FirstOrDefault();
                candidature.ServiceProvider = sp;
                candidature.Mission         = mis;
                candidature.AppDate         = DateTime.Today;
                candidature.State           = State.En_Attente;
                db.Candidatures.Add(candidature);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(candidature));
        }
Exemple #2
0
        public async Task <ActionResult> Create([Bind(Include = "ID,Texte,Title")] Candidature candidature, int Id)
        {
            if (ModelState.IsValid)
            {
                string id = User.Identity.GetUserId();
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                var user = await UserManager.FindByIdAsync(id);

                if (user == null)
                {
                    return(HttpNotFound());
                }
                string          emailAddress = user.Email;
                ServiceProvider sp           = new ServiceProvider();
                sp = db.ServiceProviders.Where(x => x.Email == emailAddress).FirstOrDefault();
                sp.Candidatures.Add(candidature);

                Mission mis = db.Missions.Where(x => x.ID == Id).FirstOrDefault();
                candidature.Mission = mis;
                db.Candidatures.Add(candidature);
                db.SaveChanges();
                return(RedirectToAction("Index", "Missions"));
            }

            return(View(candidature));
        }
Exemple #3
0
        // [ValidateAntiForgeryToken]
        public ActionResult Create(HttpPostedFileBase upload, Domain domain)
        {
            int    id = (int)TempData["ss"];
            Sector ss = db.Sectors.Where(s => s.ID == id).Single();

            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    var photo = new Photo
                    {
                        Name = System.IO.Path.GetFileName(upload.FileName),
                        Link = "~/Content/Images/" + upload.FileName,
                    };
                    //   photo.Link = "~/Helpers/" + photo.Name;
                    upload.SaveAs(Server.MapPath(photo.Link));
                    db.Photos.Add(photo);
                    Domain dm = new Domain
                    {
                        Name      = domain.Name,
                        PhotoLink = photo.Link
                    };
                    db.Domains.Add(dm);
                    ss.Domain.Add(dm);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Sectors", new { id = id }));
                }


                return(View());
            }

            return(View(domain));
        }
        public ActionResult Create([Bind(Include = "ID,FullName,UserName,Email,PhoneNum")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(client));
        }
Exemple #5
0
        //[ValidateAntiForgeryToken]
        //Method Create for the sectors
        public ActionResult Create([Bind(Include = "ID,Name")] Sector sector)
        {
            if (ModelState.IsValid)
            {
                db.Sectors.Add(sector);
                db.SaveChanges();
                return(RedirectToAction("Index", "Sectors", new { id = sector.ID }));
            }

            return(View(sector));
        }
        public ActionResult Validate(Realisation realisation)
        {
            Realisation rr = db.Realisations.Where(r => r.ID == realisation.ID).FirstOrDefault();

            rr.Validation = true;
            rr.Stars      = realisation.Stars;
            rr.Opinion    = realisation.Opinion;
            db.SaveChanges();
            return(RedirectToAction("Index", "missions"));
        }
 /// <summary>
 /// delete a mission
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult DeleteMission(int id)
 {
     try
     {
         Mission mission = db.Missions.Find(id);
         db.Missions.Remove(mission);
         var cd = db.Candidatures.Where(c => c.Mission.ID == id).ToList();
         foreach (var item in cd)
         {
             db.Candidatures.Remove(item);
         }
         db.SaveChanges();
         return(Content(Boolean.TrueString));
         //return RedirectToAction("Index");
     }
     catch
     {
         return(Content(Boolean.FalseString));
     }
 }
        public async Task <ActionResult> Create([Bind(Include = "ID,Description,TakenTime")] Realisation realisation, int id, IEnumerable <HttpPostedFileBase> files)
        {
            try
            {
                foreach (var file in files)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        var photo = new Photo
                        {
                            Name = Path.GetFileName(file.FileName),
                            Link = "~/Content/Images/" + file.FileName,
                        };
                        //   photo.Link = "~/Helpers/" + photo.Name;
                        file.SaveAs(Server.MapPath(photo.Link));
                        db.Photos.Add(photo);
                        if (realisation.Photos == null)
                        {
                            realisation.Photos = new List <Photo>();
                        }
                        realisation.Photos.Add(photo);
                    }
                }
                Mission ms = db.Missions.Find(id);
                realisation.Mission         = ms;
                realisation.Client          = ms.Client;
                realisation.ServiceProvider = ms.ServiceProvider;
                db.Realisations.Add(realisation);
                db.SaveChanges();
                string ss = await getPicLink();

                ViewBag.photoLink = ss;
                return(RedirectToAction("Index"));
            }
            catch (Exception ex) {
                return(View(realisation));
            }
        }
        public async Task <ActionResult> Create(Mission mission, FormCollection form, HttpPostedFileBase upload)
        {
            //if (ModelState.IsValid)
            //{
            //try {
            if (upload != null && upload.ContentLength > 0)
            {
                var photo = new Photo
                {
                    Name = System.IO.Path.GetFileName(upload.FileName),
                    Link = "~/Content/Images/" + upload.FileName,
                };
                //   photo.Link = "~/Helpers/" + photo.Name;
                upload.SaveAs(Server.MapPath(photo.Link));
                db.Photos.Add(photo);
                mission.PhotoLink = photo.Link;
            }
            else
            {
                mission.PhotoLink = "~/Content/Images/jobOffer.jpg";
            }
            Address ad = mission.Address;

            db.Addresses.Add(ad);
            //Finding the client who posted this mission , so to add this mission to his list of propopsitions
            string id = User.Identity.GetUserId();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var user = await UserManager.FindByIdAsync(id);

            if (user == null)
            {
                return(HttpNotFound());
            }
            string emailAddress = user.Email;
            Client cust         = new Client();

            cust = db.Clients.Where(x => x.Email == emailAddress).FirstOrDefault();
            if (cust == null)
            {
                // return HttpNotFound();
                return(Content("Although you have the customer role but you are not registerd as a Client in our database , please contact the administrators for a quick Fix , Thanks"));
            }
            //adding the mssion state and publishDate which are auomatic not manual !!
            mission.PublishDate = DateTime.Now.Date;
            mission.State       = Status.Ouverte;
            string sector = form["Sector"].ToString();
            string domain = form["Domain"].ToString();
            Domain dd     = db.Domains.Where(x => x.Name == domain).FirstOrDefault();
            Sector ss     = db.Sectors.Single(x => x.Name == sector);

            mission.Domain = dd;
            mission.Sector = ss;
            cust.Missions  = new List <Mission>();
            cust.Missions.Add(mission);
            dd.Missions.Add(mission);
            dd.MissionCount = dd.Missions.Count();
            db.Missions.Add(mission);
            db.SaveChanges();
            return(RedirectToAction("Index"));
            //}

            //catch
            //{
            //    List<SelectListItem> domainList = new List<SelectListItem>();
            //    List<SelectListItem> sectorList = new List<SelectListItem>();
            //    foreach (var item in db.Domains.ToList()) domainList.Add(new SelectListItem { Text = item.Name, Value = item.Name });
            //    foreach (var item in db.Sectors.ToList()) sectorList.Add(new SelectListItem { Text = item.Name, Value = item.Name });
            //    ViewBag.Sectors = (IEnumerable<SelectListItem>)sectorList;
            //    ViewBag.Domains = (IEnumerable<SelectListItem>)domainList;
            //    return View(mission);
            //}
        }
Exemple #10
0
        public ActionResult EduCreate(Education edu)
        {
            if (ModelState.IsValid)
            {
                string          email = (string)Session["email"];
                ServiceProvider sp    = new ServiceProvider();
                sp = db.ServiceProviders.Where(s => s.Email == email).FirstOrDefault();
                edu.ServiceProvider = sp;
                sp.Educations.Add(edu);
                db.Educations.Add(edu);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(edu));
        }
        //Create [email protected] with password=Admin@123456 in the Admin role
        public static void InitializeIdentityForEF(ApplicationDbContext db)
        {
            var          userManager = HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var          roleManager = HttpContext.Current.GetOwinContext().Get <ApplicationRoleManager>();
            const string userName    = "******";
            const string email       = "*****@*****.**";
            const string password    = "******";
            const string roleName    = "Admin";
            const string roleName1   = "Client";
            const string roleName2   = "ServiceProvider";
            //Create Role Admin if it does not exist
            var role = roleManager.FindByName(roleName);

            if (role == null)
            {
                role = new ApplicationRole(roleName);
                var roleresult = roleManager.Create(role);
            }
            //Create Role Client if it does not exist
            var role1 = roleManager.FindByName(roleName1);

            if (role1 == null)
            {
                role1 = new ApplicationRole(roleName1);
                var roleresult1 = roleManager.Create(role1);
            }
            //Create Role ServiceProvider if it does not exist
            var role2 = roleManager.FindByName(roleName2);

            if (role2 == null)
            {
                role2 = new ApplicationRole(roleName2);
                var roleresult2 = roleManager.Create(role2);
            }

            //Create default admin User
            var user = userManager.FindByEmail(email);

            if (user == null)
            {
                user = new ApplicationUser {
                    UserName = userName, Email = email
                };
                var result = userManager.Create(user, password);
                result = userManager.SetLockoutEnabled(user.Id, false);

                ContactiniContext ctx = new ContactiniContext();
                Client            cl  = new Client();
                cl.Email    = user.Email;
                cl.UserName = user.UserName;
                ctx.Clients.Add(cl);
                ctx.SaveChanges();
            }



            // Add user admin to Role Admin if not already added
            var rolesForUser = userManager.GetRoles(user.Id);

            if (!rolesForUser.Contains(role.Name))
            {
                var result = userManager.AddToRole(user.Id, role.Name);
            }
            // Add user admin to Role Client if not already added

            if (!rolesForUser.Contains(role1.Name))
            {
                var result = userManager.AddToRole(user.Id, role1.Name);
            }
        }
Exemple #12
0
        public async Task <ActionResult> _Edit([Bind(Include = "Email,FullName,UserName,Id,StreetAddress,City,State,Country,PostalCode,PhoneNumber,photoLink,isServiceProvider")] EditUserViewModel editUser, string returnUrl, params string[] Spr)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByIdAsync(editUser.Id);

                if (user == null)
                {
                    return(HttpNotFound());
                }

                ServiceProvider ss = ctx.ServiceProviders.Where(s => s.Email == user.Email).FirstOrDefault();
                Client          cc = ctx.Clients.Where(c => c.Email == user.Email).FirstOrDefault();
                if (ss != null)
                {
                    ss.Email                 = editUser.Email;
                    ss.PhoneNum              = editUser.PhoneNumber;
                    ss.UserName              = editUser.UserName;
                    ss.FullName              = editUser.FullName;
                    ss.photoLink             = editUser.PhotoLink;
                    ss.Address.StreetAddress = editUser.StreetAddress;
                    ss.Address.State         = editUser.State;
                    ss.Address.Country       = editUser.Country;
                    ss.Address.City          = editUser.City;
                    ss.Address.PostalCode    = editUser.PostalCode;
                    ss.photoLink             = editUser.PhotoLink;
                    ctx.SaveChanges();
                }
                if (cc != null)
                {
                    cc.Email    = editUser.Email;
                    cc.UserName = editUser.UserName;
                    cc.PhoneNum = editUser.PhoneNumber;
                    cc.Address.StreetAddress = editUser.StreetAddress;
                    cc.Address.City          = editUser.City;
                    cc.Address.State         = editUser.State;
                    cc.Address.PostalCode    = editUser.PostalCode;
                    cc.Address.Country       = editUser.Country;
                    cc.FullName = editUser.FullName;

                    ctx.SaveChanges();
                }
                if (cc == null)
                {
                    cc          = new Client();
                    cc.Email    = editUser.Email;
                    cc.UserName = editUser.UserName;
                    cc.PhoneNum = editUser.PhoneNumber;
                    cc.Address  = new Address();
                    cc.Address.StreetAddress = editUser.StreetAddress;
                    cc.Address.City          = editUser.City;
                    cc.Address.State         = editUser.State;
                    cc.Address.PostalCode    = editUser.PostalCode;
                    cc.Address.Country       = editUser.Country;
                    cc.FullName = editUser.FullName;
                    ctx.Clients.Add(cc);
                    ctx.SaveChanges();
                }
                user.FullName      = editUser.FullName;
                user.UserName      = editUser.UserName;
                user.Email         = editUser.Email;
                user.StreetAddress = editUser.StreetAddress;
                user.City          = editUser.City;
                user.State         = editUser.State;
                user.Country       = editUser.Country;
                user.PostalCode    = editUser.PostalCode;
                user.PhoneNumber   = editUser.PhoneNumber;
                user.PhotoLink     = editUser.PhotoLink;
                string retour = Session["retour"].ToString();;
                if (editUser.isServiceProvider && ((string)TempData["sp"] == "nonSP"))
                {
                    var result = await UserManager.AddToRoleAsync(user.Id, "ServiceProvider");

                    if (!result.Succeeded)
                    {
                        ModelState.AddModelError("", result.Errors.First());
                        return(View());
                    }
                    else
                    {
                        ServiceProvider sp = new ServiceProvider
                        {
                            Email       = user.Email,
                            FullName    = user.FullName,
                            PhoneNum    = user.PhoneNumber,
                            UserName    = user.UserName,
                            Stars       = 0,
                            photoLink   = user.PhotoLink,
                            Titre       = "Titre pas encore déterminé",
                            Description = "New Service Provider"
                        };
                        Address ad = new Address
                        {
                            StreetAddress = user.StreetAddress,
                            City          = user.City,
                            State         = user.State,
                            Country       = user.Country,
                            PostalCode    = user.PostalCode
                        };

                        // On voulais affecté une domaine et une secteur par défaut a chaque nouveau prestatatir ( c obligatoire pour
                        //évité des exception non traité au futur
                        Domain ain = ctx.Domains.Where(d => d.Name == "aucun").FirstOrDefault();
                        if (ain == null)
                        {
                            ain = new Domain {
                                Name = "aucun", PhotoLink = "~/Content/Images/dm.jpg"
                            }; ctx.Domains.Add(ain); ctx.SaveChanges();
                        }
                        Sector tor = ctx.Sectors.Where(s => s.Name == "aucun").FirstOrDefault();
                        if (tor == null)
                        {
                            tor = new Sector {
                                Name = "aucun"
                            }; tor.Domain.Add(ain); ctx.Sectors.Add(tor); ctx.SaveChanges();
                        }
                        sp.Domain = ain;
                        sp.sector = tor;



                        sp.Address = ad;
                        ctx.ServiceProviders.Add(sp);
                        ctx.Addresses.Add(ad);
                        ctx.SaveChanges();
                    }
                }
                if (!editUser.isServiceProvider && ((string)TempData["sp"] == "SP"))
                {
                    var result = await UserManager.RemoveFromRoleAsync(user.Id, "ServiceProvider");

                    if (!result.Succeeded)
                    {
                        ModelState.AddModelError("", result.Errors.First());
                        return(View());
                    }
                    // if he removed himself from the serviceProvider role , we have to return him to client reception not beck from he came
                    // because guess he's coming from monCV , back to previous page will still direct him to SP space where he doesn't belong anymore

                    /* The problem now is when he trick the app by typing the link Business/mycv wils till work since we didn't delete him from SP list ,
                     * anyway we will get back to that !*/

                    //else
                    //{
                    //    ServiceProvider sp = ctx.ServiceProviders.Where(x => x.Email == editUser.Email).FirstOrDefault();
                    //    ctx.ServiceProviders.Remove(sp);
                    //    ctx.SaveChanges();
                    //}
                }
                var rs = await UserManager.UpdateAsync(user);

                if (!rs.Succeeded)
                {
                    ModelState.AddModelError("", rs.Errors.First());
                    return(View());
                }
                if (!String.IsNullOrEmpty(returnUrl))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(RedirectToAction("Index", "Missions"));
                }


                //HttpContext.GetOwinContext().Get<ApplicationDbContext>().SaveChanges();
                //return RedirectToAction("Index","Missions");
                // return Redirect(Request.UrlReferrer.ToString());
            }
            ModelState.AddModelError("", "Something failed.");
            return(View());
        }