public ActionResult EditAvailability(EditUserViewModel model)
        {
            var user = this.Data.SupportAgents
                       .All()
                       .Where(u => u.Id == model.Id)
                       .FirstOrDefault();

            var availability = this.Data.Availabilities
                               .All()
                               .Where(a => a.AvailabilityName == model.Availability)
                               .FirstOrDefault();

            user.Availability  = availability;
            user.AvailableFrom = model.From;
            user.AvailableTo   = model.To;

            var supportAgentAvailability = new SupportAgentsAvailability
            {
                AvailabilityId = availability.Id,
                SupportAgentId = model.Id,
                StartTime      = model.From,
                EndTime        = model.To
            };

            this.Data.SupportAgentsAvailabilities.Add(supportAgentAvailability);

            this.Data.SaveChanges();

            return(this.RedirectToAction("UserProfile", "User", new { area = "" }));
        }
Пример #2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var availabilityId = this.Data.Availabilities
                                     .All()
                                     .Where(a => a.AvailabilityName == "Unavailable")
                                     .FirstOrDefault()
                                     .Id;

                var user = new SupportAgent
                {
                    UserName       = model.Email,
                    Email          = model.Email,
                    PhoneNumber    = model.PhoneNumber,
                    AvailabilityId = availabilityId,
                    AvailableFrom  = DateTime.Now
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    //// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    //// Send an email with this link
                    //// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    //// var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    //// await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    var userStore   = new UserStore <SupportAgent>(new SMSContext());
                    var userManager = new UserManager <SupportAgent>(userStore);

                    userManager.AddToRole(user.Id, "Support Agent");

                    var availability = new SupportAgentsAvailability
                    {
                        SupportAgentId = user.Id,
                        AvailabilityId = user.AvailabilityId,
                        StartTime      = user.AvailableFrom
                    };

                    this.Data.SupportAgentsAvailabilities.Add(availability);
                    user.SupportAgentAvailabilities.Add(availability);

                    this.Data.SaveChanges();

                    return(RedirectToAction("Index", "Home", new { area = "" }));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }