Exemplo n.º 1
0
        public IHttpActionResult Putmentor(int id, mentor mentor)
        {
            if (id != mentor.mentorid)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                if (!mentorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public HttpResponseMessage Postmentor(mentor mentor)
        {
            var resp     = Request.CreateResponse(HttpStatusCode.BadRequest, "Mail is registered. Please try again!");
            var response = Request.CreateResponse(HttpStatusCode.Created, "Register Successfully!");
            var result   = from a in db.mentors
                           join b in db.skills on a.idskill equals b.idskill
                           select a;
            Random random         = new Random();
            string activationCode = random.Next(100000, 999999).ToString();

            foreach (var item in result)
            {
                if (item.email == mentor.email)
                {
                    return(resp);
                }
            }
            db.mentors.Add(new mentor
            {
                name     = mentor.name,
                email    = mentor.email,
                phone    = mentor.phone,
                address  = mentor.address,
                isActive = 0,
                password = GetMD5(mentor.password),
                idskill  = mentor.idskill,
                isreceivenotification = 1,
                activationcode        = activationCode.ToString()
            });

            SmtpClient client = new SmtpClient();

            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl      = true;
            client.Host           = "smtp.gmail.com";
            client.Port           = 587;
            // setup Smtp authentication
            NetworkCredential credentials = new NetworkCredential("*****@*****.**", "meomeo123456789");

            client.UseDefaultCredentials = false;
            client.Credentials           = credentials;
            //can be obtained from your model
            MailMessage msg = new MailMessage();

            msg.From = new MailAddress("*****@*****.**");
            msg.To.Add(new MailAddress(mentor.email));                                      // Truyền người nhận

            msg.Subject    = "[khanhan123]_[" + mentor.email + "]_Cảm ơn bạn đã quan tâm!"; // Tiêu đề
            msg.IsBodyHtml = true;

            msg.Body += string.Format("<html><head></head><body><b>Click Link to CONFIRM EMAIL: </b></body>");// Nội dung mail
            msg.Body += "<br /><a href = '" + string.Format("http://localhost:59786/api/mentors/ActiveEmail/?activationcode={0}", activationCode) + "'>Click here to activate your account.</a>";

            client.Send(msg);


            db.SaveChanges();

            return(response);
        }
Exemplo n.º 3
0
        public IHttpActionResult Getmentor(int id)
        {
            mentor mentor = db.mentors.Find(id);

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

            return(Ok(mentor));
        }
Exemplo n.º 4
0
        public IHttpActionResult Deletementor(int id)
        {
            mentor mentor = db.mentors.Find(id);

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

            db.mentors.Remove(mentor);
            db.SaveChanges();

            return(Ok(mentor));
        }