public async Task <IHttpActionResult> Putuserapp(int id, userapp userapp)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userapp.id)
            {
                return(BadRequest());
            }

            db.Entry(userapp).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!userappExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public userapp Actualizar(int id, string telephone, string cellphone, string email, string contrasena)
        {
            db.Configuration.LazyLoadingEnabled = false;

            userapp user = db.userapp.Find(id);

            if (user != null)
            {
                user.telephone = telephone;
                user.cellphone = cellphone;
                user.email     = email;
                user.passw     = MD5Manager.Encrypt(contrasena, true);

                string pass = MD5Manager.Encrypt(contrasena, true);
                db.Entry(user).State = EntityState.Modified;



                db.SaveChanges();

                return(user);
            }

            return(null);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            userapp userapp = db.userapp.Find(id);

            db.userapp.Remove(userapp);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <IHttpActionResult> Getuser(int id)
        {
            userapp userapp = await db.userapp.FindAsync(id);

            if (userapp == null)
            {
                return(NotFound());
            }

            return(Ok(userapp));
        }
 public ActionResult Edit([Bind(Include = "id,id_card,name1,name2,lastname1,lastname2,birthdate,registrationdate,city,collective,telephone,cellphone,email,passw,status,securitystamp")] userapp userapp)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userapp).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.city       = new SelectList(db.city, "ID", "Name", userapp.city);
     ViewBag.collective = new SelectList(db.collective, "id", "nombre", userapp.collective);
     ViewBag.status     = new SelectList(db.user_state, "id", "name", userapp.status);
     return(View(userapp));
 }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            userapp userapp = db.userapp.Find(id);

            if (userapp == null)
            {
                return(HttpNotFound());
            }
            return(View(userapp));
        }
        public async Task <IHttpActionResult> Deleteuserapp(int id)
        {
            userapp userapp = await db.userapp.FindAsync(id);

            if (userapp == null)
            {
                return(NotFound());
            }

            db.userapp.Remove(userapp);
            await db.SaveChangesAsync();

            return(Ok(userapp));
        }
        public userapp Login(string email, string pass)
        {
            db.Configuration.LazyLoadingEnabled = false;

            pass = MD5Manager.Encrypt(pass, true);
            List <userapp> user = db.userapp.Where(r => r.email.Equals(email)).Where(r => r.passw.Equals(pass)).ToList();

            if (user.Count > 0)
            {
                userapp userapp = user.ElementAt(0);
                return(userapp);
            }

            return(null);
        }
        public void sendemail(userapp user, string email)
        {
            user.passw = CreatePassword(6);


            var          fromAddress  = new MailAddress("*****@*****.**", "Se le tiene");
            var          toAddress    = new MailAddress(user.email, "To Name");
            const string fromPassword = "******";
            const string subject      = "Cambio de contraseña";
            string       body         = "<h3>Cordial saludo</h3><h3 style=\"text-align: justify;\">Tu nueva contraseña es " + user.passw + "</p>";

            user.passw = MD5Manager.Encrypt(user.passw, true);

            db.Entry(user).State = EntityState.Modified;
            db.SaveChanges();
            try
            {
                var smtp = new SmtpClient
                {
                    Host                  = "72.29.75.91",
                    Port                  = 25,
                    EnableSsl             = false,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Timeout               = 10000,
                    Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                };
                var message = new MailMessage(fromAddress, toAddress);

                message.IsBodyHtml = true;
                message.Subject    = subject;
                message.Body       = body;



                smtp.EnableSsl = false;
                smtp.Send(message);
            }


            catch (Exception e)
            {
                Console.WriteLine("Ouch!" + e.ToString());
            }
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            db.Configuration.LazyLoadingEnabled = true;

            userapp userapp = db.userapp.Find(id);

            if (userapp == null)
            {
                return(HttpNotFound());
            }
            ViewBag.city       = new SelectList(db.city, "ID", "Name", userapp.city);
            ViewBag.collective = new SelectList(db.collective, "id", "nombre", userapp.collective);
            ViewBag.status     = new SelectList(db.user_state, "id", "name", userapp.status);
            return(View(userapp));
        }
Esempio n. 11
0
        public async Task <IHttpActionResult> Postuserapp(userapp userapp)
        {
            db.Configuration.LazyLoadingEnabled = false;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                List <userapp> user = db.userapp.Where(r => r.email.Equals(userapp.email)).ToList();
                if (user.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, "Usuario existente"));
                }
                userapp.passw  = MD5Manager.Encrypt(userapp.passw, true);
                userapp.status = 1;
                db.userapp.Add(userapp);
                await db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            return(Ok(userapp));
        }