コード例 #1
0
        public ActionResult <UserTable> Unread([FromBody] List <EmailTable> modelList)
        {
            Response response = new Response();

            using (EmailDatabaseContext context = new EmailDatabaseContext())
            {
                foreach (EmailTable model in modelList)
                {
                    EmailTable emailRecordInDb = context.EmailTable.Where(eml => eml.Id == model.Id).SingleOrDefault();

                    if (ModelState.IsValid)
                    {
                        if (emailRecordInDb != null)
                        {
                            emailRecordInDb.IsRead = false;
                            context.SaveChanges();
                            response.isOk    = true;
                            response.message = "Email is unread.";
                        }
                    }
                }
            }

            return(Content(JsonConvert.SerializeObject(response)));
        }
コード例 #2
0
        public ActionResult <UserTable> ChangePassword([FromBody] UserTable model)
        {
            Response response = new Response();

            using (EmailDatabaseContext context = new EmailDatabaseContext())
            {
                UserTable userRecordInDb = context.UserTable.Where(u => u.Email == model.Email).SingleOrDefault();

                if (ModelState.IsValid)
                {
                    if (userRecordInDb != null)
                    {
                        if (userRecordInDb.Password == model.Password)
                        {
                            response.isOk    = false;
                            response.message = "Password cannot be same.";
                        }

                        else
                        {
                            userRecordInDb.Password = model.Password;
                            context.SaveChanges();
                            response.isOk    = true;
                            response.message = "Password for " + userRecordInDb.Email + " has been changed.";
                        }
                    }
                }
            }


            return(Content(JsonConvert.SerializeObject(response)));
        }
コード例 #3
0
        public ActionResult <EmailTable> Send([FromBody] EmailTable model)
        {
            using (EmailDatabaseContext context = new EmailDatabaseContext())
            {
                Response response = new Response();
                if (ModelState.IsValid)
                {
                    context.EmailTable.Add(model);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (NullReferenceException ex)
                    {
                        response.message = ex.ToString();
                        response.isOk    = false;

                        return(Content(JsonConvert.SerializeObject(response)));
                    }
                }

                response.message = "Mail sent.";
                response.isOk    = true;

                return(Content(JsonConvert.SerializeObject(response)));
            }
        }
コード例 #4
0
        public ActionResult <UserTable> SignUpPost([FromBody] UserTable model)
        {
            Response response = new Response();

            using (EmailDatabaseContext context = new EmailDatabaseContext())
            {
                var userWithSameEmail = context.UserTable.Where(u => u.Email == model.Email).SingleOrDefault(); //checking if the email already exits for any user


                if (ModelState.IsValid)
                {
                    if (userWithSameEmail == null)
                    {
                        context.UserTable.Add(model);
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (NullReferenceException ex)
                        {
                            response.message = ex.ToString();
                            response.isOk    = false;
                            return(Content(JsonConvert.SerializeObject(response)));
                        }
                    }
                    else
                    {
                        response.message = "User with this Email Already Exists.";
                        response.isOk    = false;
                        return(Content(JsonConvert.SerializeObject(response)));
                    }
                }
            }
            response.message = model.Name + " " + model.Surname + " registered succesfully.";
            response.isOk    = true;
            return(Content(JsonConvert.SerializeObject(response)));
        }