public async Task<IActionResult> ExecuteAsync(SaveContactUs saveContactUs, CancellationToken cancellationToken)
        {
            //var user = _httpContextAccessor.HttpContext.User;
            //if (user == null)
            //    return new NotFoundResult();

            //var claims = user.Claims.ToList();
            //if (claims.Count < 1)
            //    return new NotFoundResult();

            //// Lấy Id của người dùng
            //var userId = claims.FirstOrDefault(claimRecord => claimRecord.Type == "sub")?.Value;

            var contactUs = _saveContactUsToContactUsMapper.Map(saveContactUs);
            //contactUs.CreatedBy = userId;
            //contactUs.ModifiedBy = userId;

            contactUs = await _contactUsRepository.Add(contactUs, cancellationToken);
            var contactUsViewModel = _contactUsToContactUsMapper.Map(contactUs);

            return new CreatedAtRouteResult(
                ContactUsControllerRoute.GetContactUs,
                new { ContactUsId = contactUsViewModel.Id },
                contactUsViewModel);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(ViewContactUs contactUs, string lang)
        {
            var contactUsModel = _dataAccessService.PageContact.FirstOrDefault();

            if (lang == null || lang.ToLower() == "ar")
            {
                ViewBag.Title = contactUsModel.ArPageName;
            }
            else
            {
                ViewBag.Title = contactUsModel.ArPageName;
            }
            var items = _dataAccessService.PageContact.Where(i => i.IsDeleted != true && i.IsActive == true).OrderBy(i => i.Id).First();

            if (ModelState.IsValid)
            {
                ContactUs contact = _contactUsRepository.Add(contactUs.MapToPageViewContact());
                if (contact != null)
                {
                    var sentMail = await _myEmailSender.SendEmailAsync(contactUsModel.EmailParticipateEmail, contactUsModel.EmailParticipateEmail, contact.Topic ?? "", contact.Message ?? "");

                    if (sentMail)
                    {
                        var msg = lang == "en" ? "Submitted Successfully" : "تم الارسال";
                        _toastNotification.AddSuccessToastMessage(msg);
                        ModelState.Clear();
                        return(View(items.MapToPageContact()));
                    }
                    var msg2 = lang == "en" ? "Failed to Submit" : "حدث خطأ فل الارسال";
                    _toastNotification.AddErrorToastMessage(msg2);
                    ModelState.Clear();
                    return(View(items.MapToPageContact()));
                }
                else
                {
                    _toastNotification.AddErrorToastMessage("See Validation Errors");
                    ModelState.Clear();
                    return(View(items.MapToPageContact()));
                }
            }
            _toastNotification.AddErrorToastMessage("See Validation Errors");
            ModelState.Clear();
            return(View(items.MapToPageContact()));
        }
        public ActionResult SaveContact([System.Web.Http.FromBody] ContactUsModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            if (Validator.validate(model))
            {
                try
                {
                    // model mapping (TODO: use automapper here)
                    ContactUs mappedModel = new ContactUs
                    {
                        Id            = Guid.NewGuid(),
                        Name          = model.Name,
                        Email         = model.Email,
                        Mobile        = model.Mobile,
                        MessageTypeId = model.MessageTypeId,
                        Message       = model.Message,
                        FilePath      = model.FilePath,
                        CreateDate    = DateTime.Now
                    };

                    _contactUsRepository.Add(mappedModel);

                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception)
                {
                    return(Json(new { success = false, message = "Unable to save, please try again later." }, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(new { success = false, message = "Unable to save, please try again later." }, JsonRequestBehavior.AllowGet));
        }