Beispiel #1
0
        public async Task <IActionResult> Index(ContactMessageBindingModel model)
        {
            var user = this.User.Identity.IsAuthenticated
               ? await this.userManager.GetUserAsync(this.User)
               : null;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var serviceModel = Mapper.Map <ContactMessageServiceModel>(model);

            serviceModel.UserId = user?.Id;

            var result = await this.contactMessagesService.CreateAsync(serviceModel);

            if (!result)
            {
                this.Error(NotificationMessages.ContactMessageError);

                return(View(model));
            }

            this.Success(NotificationMessages.ContactMessageSuccess);

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #2
0
        public async Task <IActionResult> Index()
        {
            var user = this.User.Identity.IsAuthenticated
                ? await this.userManager.GetUserAsync(this.User)
                : null;

            if (user == null)
            {
                return(this.View());
            }

            var model = new ContactMessageBindingModel
            {
                FullName = $"{user.FirstName} {user.LastName}",
                Email    = user.Email
            };

            return(this.View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> Index(ContactMessageBindingModel model)
        {
            var user = this.User.Identity.IsAuthenticated
                ? await this.userManager.GetUserAsync(this.User)
                : null;

            if (!this.ModelState.IsValid)
            {
                if (user != null)
                {
                    model.FullName = $"{user.FirstName} {user.LastName}";
                    model.Email    = user.Email;
                }

                return(this.View(model));
            }

            var serviceModel = Mapper.Map <ContactMessageServiceModel>(model);

            serviceModel.UserId = user?.Id;

            var result = await this.contactMessagesService.CreateAsync(serviceModel);

            if (!result)
            {
                this.Error(NotificationMessages.ContactMessageCreateError);

                if (user != null)
                {
                    model.FullName = $"{user.FirstName} {user.LastName}";
                    model.Email    = user.Email;
                }

                return(this.View(model));
            }

            this.Success(NotificationMessages.ContactMessageCreated);
            return(this.RedirectToAction("Index", "Home"));
        }