Пример #1
0
        public async Task <IActionResult> AddUser(RegisterViewModel model)
        {
            var          userId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            Organisation org    = dbcontext.Organisation.Where(m => m.ApplicationUserId == userId).FirstOrDefault();

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserRole     = model.UserRole,
                    EmployeeName = model.EmployeeName,
                    Usernames    = model.Usernames,
                    Status       = model.Status,
                    Email        = model.Email,
                    UserName     = model.Email,
                    PhoneNumber  = model.PhoneNumber,
                };

                var results = await _userManager.CreateAsync(user, model.Password);

                if (results.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, user.UserRole);

                    OtherUser otherUser = new OtherUser()
                    {
                        Id             = Guid.NewGuid(),
                        OrganisationId = org.Id,
                        UserId         = Guid.Parse(user.Id),
                        HostId         = org.ApplicationUserId
                    };

                    dbcontext.Add(otherUser);
                    dbcontext.SaveChanges();
                    //Send Mail After Employee Creation
                    //SmtpClient client = new SmtpClient("smtp.office365.com"); //set client
                    //client.Port = 587;
                    //client.EnableSsl = true;
                    //client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    //client.UseDefaultCredentials = false;
                    //client.Credentials = new NetworkCredential("*****@*****.**", "@Devops19"); //Mailing credential
                    ////mail body
                    //MailMessage mailMessage = new MailMessage();
                    //mailMessage.From = new MailAddress("*****@*****.**");
                    //mailMessage.To.Add(model.Email); //Trainee mail here
                    //mailMessage.Body = "Hello " + model.EmployeeName + " You have just been onboarded on ERP4SME, Your email is " + model.Email + ". Please confirm your account by clicking this link: erp.com.";
                    //mailMessage.Subject = "MISTDO Account Created";
                    //client.Send(mailMessage);

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View());
        }
Пример #2
0
        public IActionResult leavetheaddedcenter(int centerId)
        {
            //this line codes below is stating that.
            //first we call our store session function
            //now we do our query thru our third table and look for the fanid or user and if matches with the gameid then we can now remove it

            User current = GetUser();

            if (current == null)
            {
                return(Redirect("/Home"));
            }

            OtherUser leavingthecenter = _context.OtherUsers
                                         .FirstOrDefault(o => o.UserId == current.UserId && o.CenterId == centerId);

            _context.OtherUsers.Remove(leavingthecenter);
            _context.SaveChanges();

            return(Redirect("/Dashboard"));
        }
Пример #3
0
        public IActionResult addingcentertoexerciseorjoiningthecenter(int centerId)
        {
            User current = GetUser();

            if (current == null)
            {
                return(Redirect("/Home"));
            }

            //now linking my manay to many join whereby creating a new variable and giving it to my third table or assigning it.
            //then calling that variable and assigning our user or fan id to the current one we stored in session.
            //now we do the adding of many to many join

            OtherUser joiningotheruseractivitycenter = new OtherUser();

            joiningotheruseractivitycenter.UserId   = current.UserId;
            joiningotheruseractivitycenter.CenterId = centerId;
            _context.OtherUsers.Add(joiningotheruseractivitycenter);
            _context.SaveChanges();
            ViewBag.Fan = current;

            return(Redirect("/Dashboard"));
        }