Esempio n. 1
0
        public IHttpActionResult GetAll()
        {
            var users = database.Get <User>();

            if (users == null)
            {
                return(BadRequest());
            }

            return(Ok(users));
        }
Esempio n. 2
0
        public IHttpActionResult AddRequest([FromBody] AddPostViewModel postViewModel)
        {
            if (postViewModel == null)
            {
                return(BadRequest());
            }

            var newPost = new Request()
            {
                Submitter = database.Get <User>().SingleOrDefault(u => u.Email == HttpContext.Current.User.Identity.Name),
                Summary   = postViewModel.Summary,
                Details   = postViewModel.Details
            };

            database.Add(newPost);
            database.CommitAsync <Post>();

            return(Ok(newPost));
        }
Esempio n. 3
0
        public IHttpActionResult SendEmail()
        {
            var addresses = new List <string>();

            addresses.Add("*****@*****.**");
            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("*****@*****.**");

            foreach (var address in addresses)
            {
                mail.To.Add(address);
            }

            mail.Subject = "Cadre Test Email";

            var builder = new EmailBodyBuilder();

            var viewModels = new List <PostViewModel>();
            var posts      = database.Get <Post>();

            viewModels.AddRange(posts.Select(post => new PostViewModel()
            {
                Id             = post.Id,
                SubmitterName  = post.Submitter.Name,
                SubmitterEmail = post.Submitter.Email,
                Summary        = post.Summary,
                Details        = post.Details
            }));

            foreach (var viewModel in viewModels)
            {
                viewModel.EmailText = database.Get <Post>().SingleOrDefault(post => post.Id == viewModel.Id).GetEmailText();
            }

            mail.Body       = builder.Build(viewModels);
            mail.IsBodyHtml = true;

            SendSmtpEmail(mail);

            return(Ok(mail));
        }