public async Task <IHttpActionResult> Upload(int id) { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var urlImage = string.Empty; var provider = new MultipartMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider); foreach (var file in provider.Contents) { var filename = file.Headers.ContentDisposition.FileName.Trim('\"'); var buffer = await file.ReadAsByteArrayAsync(); //Do whatever you want with filename and its binaray data. urlImage = AwsBucket.StoreImage(buffer, filename); } var _guideService = new Services.GuideService(); var article = _guideService.GetArticle(id); article.BackgroundImageUrl = urlImage; _guideService.PostArticle(article); return(Json(urlImage)); }
public ActionResult Photos() { var model = new PhotosViewModel { Photos = AwsBucket.GetImages() }; return(View(model)); }
public IHttpActionResult Remove(int id, FileRequest request) { if (string.IsNullOrEmpty(request.Key)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var key = request.Key.Substring(request.Key.Length - 40); AwsBucket.RemoveImage(key); var _guideService = new Services.GuideService(); var article = _guideService.GetArticle(id); article.BackgroundImageUrl = null; _guideService.PostArticle(article); return(Json("")); }
public ActionResult Edit(Article model) { if (model.UploadImage != null) { var url = AwsBucket.StoreImage(model.UploadImage); model.BackgroundImageUrl = url; } if (string.IsNullOrEmpty(model.BackgroundImageUrl)) { model.BackgroundImageUrl = string.Empty; } model.UserId = User.Identity.GetUserId <int>(); var success = _guideService.PostArticle(model); if (!success) { return(RedirectToAction("Error")); } return(RedirectToAction("Index")); }
//create an estimate public object Post(CreateEstimateRequest request) { if (request == null || string.IsNullOrWhiteSpace(request.Address)) { throw new ArgumentException("Missing parameter 'Address'"); } if (string.IsNullOrWhiteSpace(request.City)) { throw new ArgumentException("Missing parameter 'City'"); } if (string.IsNullOrWhiteSpace(request.State)) { throw new ArgumentException("Missing parameter 'State'"); } if (string.IsNullOrWhiteSpace(request.PostalCode)) { throw new ArgumentException("Missing parameter 'PostalCode'"); } //Validate logged in user var user = ValidateAndGetCurrentUser(); User premiumUser = new User(); //try to pull the email from the user, and if not pull the anonymous from the request var email = user.Email; if (!string.IsNullOrEmpty(request.AnonymousEmail)) { email = request.AnonymousEmail; } //if we didnt get an email from either, null it out so it doesnt hit the db if (!email.Contains("@")) { email = null; } // If Premium User has this postal Code if (request.PremiumAgentId != null) { premiumUser = Db.Select <User>(u => u.PremiumAgentId == request.PremiumAgentId).FirstOrDefault(); if (premiumUser != null) { var postalCodes = PostalCodesForUser(premiumUser.Id); if (!postalCodes.Contains(request.PostalCode)) { request.PremiumAgentId = null; } } } //setup the new estimate var estimate = new Estimate { Address = request.Address, City = request.City, State = request.State, PostalCode = request.PostalCode, UnitNumber = request.UnitNumber, Notes = request.Notes, CreatedOn = DateTime.UtcNow, User = user, AssociatedEmail = email, AccessToken = Guid.NewGuid(), Active = true, PremiumAgentId = request.PremiumAgentId }; //save and return it Db.Save <Estimate>(estimate, true); var query = Db.From <PushDevice>(); query.Join <PushDevice, AgentPostalCode>((push, postal) => push.UserId == postal.UserId); query.Where <AgentPostalCode>(p => p.PostalCode == estimate.PostalCode); var devicesToPush = Db.Select(query); //Parallel.ForEach(devicesToPush, device => //{ // SendPush($"There is a new estimate request in {estimate.PostalCode}.", device); //}); bool onlyPremium = !String.IsNullOrWhiteSpace(estimate.PremiumAgentId); var agentDashboardUrl = $"{BaseEndpoint}dashboard/properties/{estimate.Id}"; if (onlyPremium && premiumUser != null) { // Notify only premium user Task premiumEmailTask = new Task(() => { var subject = $"New estimate request for zip code {estimate.PostalCode} ({estimate.City}, {estimate.State})"; var body = $"A new estimate request has been submitted for the property at:\r\n{estimate.Address} {estimate.UnitNumber}\r\n{estimate.City}, {estimate.State}, {estimate.PostalCode}\r\n\r\nClick here to respond:\r\n{agentDashboardUrl}"; SendEmailFromSupport(premiumUser.Email, subject, body); }); premiumEmailTask.Start(); premiumEmailTask.Wait(); } else { //find agents to notify var emailQuery = Db.From <User>(); emailQuery.Select(u => u.Email); emailQuery.Join <User, AgentPostalCode>((u, postal) => u.Id == postal.UserId); emailQuery.Where <AgentPostalCode>(p => p.PostalCode == estimate.PostalCode); var emailsToSendTo = Db.ColumnDistinct <string>(emailQuery).Distinct(); Console.WriteLine(Db.GetLastSql()); //TODO: This is going to go over our email quota **easily** //the SendEmailFromSupport method must be re-written to store pending emails in a queue //which can be background processed at a later time Parallel.ForEach(emailsToSendTo, agentEmail => { var subject = $"New estimate request for zip code {request.PostalCode} ({request.City}, {request.State})"; var body = $"A new estimate request has been submitted for the property at:\r\n{request.Address} {estimate.UnitNumber}\r\n{request.City}, {request.State}, {request.PostalCode}\r\n\r\nClick here to respond:\r\n{agentDashboardUrl}"; SendEmailFromSupport(agentEmail, subject, body); }); } //email the admins Task emailTask = new Task(() => { var to = "*****@*****.**"; //var to = "*****@*****.**"; var subject = $"New estimate request for zip code {request.PostalCode} ({request.City}, {request.State})"; var body = $"{user.FirstName} {user.LastName} has requested an estimate for the property at:\r\n{request.Address}\r\n{request.City}, {request.State}, {request.PostalCode}\r\nThey included {request.PictureCount} pictures.\r\n\r\nThere are {devicesToPush.Count} agents in this service area.\r\nhttp://dashboard.homingin.co/estimates/{estimate.Id}"; if (!AwsBucket.ToLower().Contains("devel")) { SendEmailFromSupport(to, subject, body); } }); emailTask.Start(); emailTask.Wait(); //email the user an email to view the listing if (!string.IsNullOrWhiteSpace(request.AnonymousEmail)) { emailTask = new Task(() => { var estimateLink = $"{BaseEndpoint}valuations/{estimate.AccessToken}"; var to = request.AnonymousEmail; var subject = $"Valuation request for: {request.Address}, {request.City}, {request.State}"; var body = $"Congratulations! You've submitted a request for a home value. Nearby real estate agents are hard at work determining your home's current market value. As they send in their responses, you'll be notified.\r\n\r\nIn order to be able to see the responses, you'll need to use this link to navigate back to your request\r\n\r\n{estimateLink}\r\n\r\nFrom your user dashboard you can create an account that will let you log in if you lose this email or if you want to display them on our mobile app. Don't worry, we don't share your information with anyone\r\n\r\nAlso, if you're thinking of selling and want to talk to one of the agents that gave you a home value, their contact information is readily available for you. Just give them a call anytime.\r\n\r\nThanks for using our home valuation service!\r\n\r\nTodd Miller\r\nCEO Co-Founder\r\n5580 S Ft Apache #120\r\nLas Vegas, NV 89148\r\[email protected]"; SendEmailFromSupport(to, subject, body); }); emailTask.Start(); emailTask.Wait(); } return(new CreateEstimateResponse { EstimateId = estimate.Id }); }