public ActionResult Create([Bind(Include = "identification,name,last_name,state,photo_id,email,address,phone_number,link,description")] Voluntary voluntary, Boolean state, HttpPostedFileBase File, string nameFile, string description)
        {
            var query = (from r in db.Voluntary where r.identification == voluntary.identification select r).Count();

            if (query == 1)
            {
                return(RedirectToAction("Create/" + voluntary.identification, new { mensaje = "El voluntario con la identificación " + voluntary.identification + " ya se encuentra registrado en el sistema" }));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    voluntary.state = state;

                    if (File == null)
                    {
                        ViewBag.MessagePhoto = "Debe ingresar una imagen";
                        return(View());
                    }
                    else
                    {
                        if (nameFile == "")
                        {
                            ViewBag.MessagePhotoName = "Debe ingresar un nombre";
                            ViewBag.MessagePhoto     = "Debe ingresar una imagen";
                            return(View());
                        }
                        else
                        {
                            var extension = Path.GetExtension(File.FileName);
                            var path      = Path.Combine(Server.MapPath("/Static/"), nameFile + extension);

                            var Photo = new DB.Photo();
                            Photo.name  = nameFile;
                            Photo.image = nameFile + extension;
                            File.SaveAs(path);

                            db.Photo.Add(Photo);

                            voluntary.description = description;
                            db.Voluntary.Add(voluntary);
                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index", new { mensaje = "El voluntario " + voluntary.name + " " + voluntary.last_name + " ha sido ingresado exitosamente" }));
                }
            }

            return(View(voluntary));
        }
        public ActionResult Create([Bind(Include = "identification,name,last_name,email,phone_number,description,photo_id")] Sponsor sponsor, HttpPostedFileBase File, string nameFile)
        {
            if (ModelState.IsValid)
            {
                var query = (from r in db.Sponsor where r.identification == sponsor.identification select r).Count();
                if (query == 1)
                {
                    return(RedirectToAction("Create", new { message = "El patrocinador con la identificación " + sponsor.identification + " ya se encuentra registrado" }));
                }
                else
                {
                    if (File == null)
                    {
                        ViewBag.message = "Debe ingresar una imagen";
                        return(View(sponsor));
                    }
                    else
                    {
                        if (nameFile == "")
                        {
                            ViewBag.message = "Debe ingresar un nombre para la imagen";
                            return(View(sponsor));
                        }
                        else
                        {
                            var extension = Path.GetExtension(File.FileName);
                            var path      = Path.Combine(Server.MapPath("/Static/"), nameFile + extension);

                            var Photo = new DB.Photo();
                            Photo.name  = nameFile;
                            Photo.image = nameFile + extension;
                            File.SaveAs(path);

                            db.Photo.Add(Photo);
                            db.SaveChanges();

                            sponsor.photo_id = Photo.id;

                            db.Sponsor.Add(sponsor);
                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index", new { message = "El patrocinador ha sido registrado exitosamente" }));
                }
            }
            return(View());
        }
        public ActionResult Create([Bind(Include = "id,name,descripcion,start_date,end_date")]
                                   Activity activity, List <string> sponsors, List <string> users, List <string> voluntaries, HttpPostedFileBase File, string nameFile)
        {
            //refill the lists
            List <Sponsor>   sponsorReturn   = db.Sponsor.ToList();
            List <User>      userReturn      = db.User.ToList();
            List <Voluntary> voluntaryReturn = db.Voluntary.ToList();
            List <Photo>     photoVerify     = db.Photo.ToList();

            if (ModelState.IsValid)
            {
                //if the sponsors list are fill
                if (sponsors != null)
                {
                    if (sponsors.Count > 0)
                    {
                        System.Collections.IList listSponsors = sponsors;
                        for (int i = 0; i < listSponsors.Count; i++)
                        {
                            string  id      = "" + listSponsors[i];
                            Sponsor sponsor = db.Sponsor.Find(id);
                            activity.Sponsor.Add(sponsor);
                        }
                    }
                }

                //if the users list are empty
                if (users == null)
                {
                    //if the sponsors list are fill so fill the viewbag
                    if (sponsors != null)
                    {
                        System.Collections.IList listSponsors = sponsors;
                        for (int i = 0; i < listSponsors.Count; i++)
                        {
                            string  id      = "" + listSponsors[i];
                            Sponsor sponsor = db.Sponsor.Find(id);
                            activity.Sponsor.Add(sponsor);
                        }
                    }
                    //if the voluntaries list are fill so fill the viewbag
                    if (voluntaries != null)
                    {
                        System.Collections.IList listVoluntaries = voluntaries;
                        for (int i = 0; i < listVoluntaries.Count; i++)
                        {
                            string    id        = "" + listVoluntaries[i];
                            Voluntary voluntary = db.Voluntary.Find(id);
                            activity.Voluntary.Add(voluntary);
                        }
                    }
                    //if the nameFile is different of null so fill the viewbag
                    if (nameFile != "")
                    {
                        ViewBag.name = nameFile;
                    }


                    //refill the lists
                    ViewBag.sponsors    = sponsorReturn;
                    ViewBag.users       = userReturn;
                    ViewBag.voluntaries = voluntaryReturn;

                    ViewBag.message = "Debe seleccionar al menos un usuario";
                    return(View(activity));
                }

                //if the user list are fill
                else
                {
                    System.Collections.IList listUsers = users;
                    for (int i = 0; i < listUsers.Count; i++)
                    {
                        string id   = "" + listUsers[i];
                        User   user = db.User.Find(id);
                        activity.User.Add(user);
                    }
                }

                //if the voluntaries are fill
                if (voluntaries != null)
                {
                    if (voluntaries.Count > 0)
                    {
                        System.Collections.IList listVoluntaries = voluntaries;
                        for (int i = 0; i < listVoluntaries.Count; i++)
                        {
                            string    id        = "" + listVoluntaries[i];
                            Voluntary voluntary = db.Voluntary.Find(id);
                            activity.Voluntary.Add(voluntary);
                        }
                    }
                }

                //if the photo file is empty
                if (File == null)
                {
                    //if the name file is different of null fill the viewbag
                    if (nameFile != "")
                    {
                        ViewBag.name = nameFile;
                    }

                    //refill the lists
                    ViewBag.sponsors    = sponsorReturn;
                    ViewBag.users       = userReturn;
                    ViewBag.voluntaries = voluntaryReturn;
                    ViewBag.message     = "Debe ingresar una imagen";
                    return(View(activity));
                }

                //if the File is fill
                else
                {
                    //but the name file is empty
                    if (nameFile == "")
                    {
                        //refill the lists
                        ViewBag.sponsors    = sponsorReturn;
                        ViewBag.users       = userReturn;
                        ViewBag.voluntaries = voluntaryReturn;
                        ViewBag.message     = "Debe ingresar un nombre de imagen";
                        return(View(activity));
                    }

                    //if the file is fill and name too
                    else
                    {
                        foreach (Photo photo in photoVerify)
                        {
                            //if(nameFile == photo.image)
                        }

                        //add the image in the folder, in the activity and database
                        var extension = Path.GetExtension(File.FileName);
                        var path      = Path.Combine(Server.MapPath("/Static/"), nameFile + extension);

                        var Photo = new DB.Photo();
                        Photo.name  = nameFile;
                        Photo.image = nameFile + extension;
                        File.SaveAs(path);

                        db.Photo.Add(Photo);

                        db.Activity.Add(activity);
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index", new { message = "La actividad se ingresó exitosamente" }));
            }


            return(View(activity));
        }
        public ActionResult Create([Bind(Include = "identification,name,last_name,email,phone_number,user_name,password,address,description,link")] User user, HttpPostedFileBase File, string nameFile)
        {
            if (ModelState.IsValid)
            {
                if (File == null)
                {
                    ViewBag.message = "Debe ingresar una imagen";

                    return(View());
                }
                else
                {
                    if (nameFile == "")
                    {
                        ViewBag.message = "Debe ingresar un nombre de imagen";

                        return(View());
                    }
                    else
                    {
                        if (nameFile == "")
                        {
                            ViewBag.message = "Debe ingresar un nombre de imagen";
                            return(View());
                        }
                        else
                        {
                            var extension = Path.GetExtension(File.FileName);
                            var path      = Path.Combine(Server.MapPath("/Static/"), nameFile + extension);

                            var Photo = new DB.Photo();
                            Photo.name  = nameFile;
                            Photo.image = nameFile + extension;
                            File.SaveAs(path);

                            db.Photo.Add(Photo);


                            db.SaveChanges();
                            user.Photo    = Photo;
                            user.photo_id = Photo.id;
                        }
                    }
                    user.password = Protection.Encrypt(user.password);

                    db.User.Add(user);
                    try
                    {
                        db.SaveChanges();
                        return(RedirectToAction("Index", new { message = "El usuario se ingresó exitosamente" }));
                    }
                    catch (Exception e)
                    {
                        ViewBag.message = "Ya existe un usuario con esta Identificación";
                        return(View());
                    }
                }
            }

            return(View(user));
        }