예제 #1
0
        public ActionResult Answer(int id)
        {
            Enquiry enquiry = db.Enquiries.FirstOrDefault(u => u.Id.Equals(id));
            AnswerEnquiryViewModel answerEnquiryViewModel = new AnswerEnquiryViewModel()
            {
                Id         = enquiry.Id,
                Answer     = enquiry.Answer,
                Question   = enquiry.Question,
                Customer   = enquiry.Customer,
                SalesStaff = enquiry.SalesStaff,
                Title      = enquiry.Title
            };

            return(View(answerEnquiryViewModel));
        }
예제 #2
0
        public ActionResult Answer(AnswerEnquiryViewModel answerEnquiryViewModel)
        {
            User user       = db.Users.FirstOrDefault(u => u.Username.Equals(User.Identity.Name, StringComparison.CurrentCultureIgnoreCase));
            var  salesStaff = db.SalesStaffs.FirstOrDefault(u => u.UserId.Equals(user.Id));
            var  enquiry    = db.Enquiries.FirstOrDefault(u => u.Id.Equals(answerEnquiryViewModel.Id));

            enquiry.Answer     = answerEnquiryViewModel.Answer;
            enquiry.SalesStaff = salesStaff;

            try
            {
                db.Enquiries.AddOrUpdate(enquiry);
                db.SaveChanges();
                TempData["MessageClass"] = "alert-success";
                TempData["Message"]      = "Successfully responded to enquiry.";
            }
            catch (Exception ex)
            {
                TempData["MessageClass"] = "alert-warning";
                TempData["Message"]      = "Something went wrong. Try again later.";
            }

            return(RedirectToAction("Unanswered"));
        }