public async Task <ActionResult> DeleteConfirmed(int id)
        {
            ContactUserModel contactUserModel = await db.ContactUserModels.FindAsync(id);

            db.ContactUserModels.Remove(contactUserModel);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,UserName,UserEmail,UserResume")] ContactUserModel contactUserModel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(contactUserModel).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(contactUserModel));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,UserName,UserEmail,UserResume")] ContactUserModel contactUserModel)
        {
            if (ModelState.IsValid)
            {
                db.ContactUserModels.Add(contactUserModel);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(contactUserModel));
        }
        // GET: Admin/ContactUserModels/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ContactUserModel contactUserModel = await db.ContactUserModels.FindAsync(id);

            if (contactUserModel == null)
            {
                return(HttpNotFound());
            }
            return(View(contactUserModel));
        }
        public async Task <ActionResult> ContactUser(ContactUserModel model)
        {
            var listing = await _listingService.FindAsync(model.ListingID);

            var userIdCurrent = User.Identity.GetUserId();
            var user          = userIdCurrent.User();

            // Check if user send message to itself, which is not allowed
            if (listing.UserID == userIdCurrent)
            {
                TempData[TempDataKeys.UserMessageAlertState] = "bg-danger";
                TempData[TempDataKeys.UserMessage]           = "[[[You cannot send message to yourself!]]]";
                return(RedirectToAction("Listing", "Listing", new { id = model.ListingID }));
            }

            // Send message to user
            var message = new MessageSendModel()
            {
                UserFrom  = userIdCurrent,
                UserTo    = listing.UserID,
                Subject   = listing.Title,
                Body      = model.Message,
                ListingID = listing.ID
            };

            await MessageHelper.SendMessage(message);

            // Send email with notification
            var emailTemplateQuery = await _emailTemplateService.Query(x => x.Slug.ToLower() == "privatemessage").SelectAsync();

            var emailTemplate = emailTemplateQuery.Single();

            dynamic email = new Postal.Email("Email");

            email.To      = user.Email;
            email.From    = CacheHelper.Settings.EmailAddress;
            email.Subject = emailTemplate.Subject;
            email.Body    = emailTemplate.Body;
            email.Message = model.Message;
            EmailHelper.SendEmail(email);

            TempData[TempDataKeys.UserMessage] = "[[[Message sent succesfully!]]]";

            return(RedirectToAction("Listing", "Listing", new { id = model.ListingID }));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> ContactUser(ContactUserModel model)
        {
            var emailTemplateQuery = await _emailTemplateService.Query(x => x.Slug.ToLower() == "privatemessage").SelectAsync();

            var emailTemplate = emailTemplateQuery.Single();

            dynamic email = new Postal.Email("Email");

            email.To      = CacheHelper.Settings.EmailContact;
            email.From    = CacheHelper.Settings.EmailContact;
            email.Subject = emailTemplate.Subject;
            email.Body    = emailTemplate.Body;
            email.Message = model.Message;
            EmailHelper.SendEmail(email);

            TempData[TempDataKeys.UserMessage] = "[[[Message sent succesfully!]]]";

            return(RedirectToAction("Listing", "Listing", new { id = model.ListingID }));
        }