Ejemplo n.º 1
0
        public IActionResult SignUp([FromBody] SignUpModelView SignUpModelView)
        {
            var result = Json(new RequestResult
            {
                State = RequestState.Failed,
                Msg   = "Ops, something wrong! Please check the information and try again!"
            });

            if (SignUpModelView.CourseId > 0 && !string.IsNullOrEmpty(SignUpModelView.StudentName) && SignUpModelView.StudentAge > 0)
            {
                lock (addLock)
                {
                    var course  = _coursesRepository.GetById(SignUpModelView.CourseId);
                    var student = _usersRepository.RegisterOrUpdate(SignUpModelView.StudentName, SignUpModelView.StudentAge);

                    if (course != null && student != null)
                    {
                        if (course != null && course.Students.Any(c => c.Name == SignUpModelView.StudentName))
                        {
                            result = Json(new RequestResult
                            {
                                State = RequestState.Failed,
                                Msg   = "Student already enrolled in this course"
                            });
                        }
                        if (course.Students == null || course.Students.Count < course.MaxStudents)
                        {
                            _coursesRepository.SignUp(course, student);


                            result = Json(new RequestResult
                            {
                                State = RequestState.Success,
                                Msg   = "Student successfully enrolled"
                            });
                        }
                        else
                        {
                            result = Json(new RequestResult
                            {
                                State = RequestState.Failed,
                                Msg   = "Sorry, the Course is full"
                            });
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SignUpAsync([FromBody] SignUpModelView SignUpModelView)
        {
            var result = Json(new RequestResult
            {
                State = RequestState.Failed,
                Msg   = "Ops, something wrong! please check the information and try again!"
            });

            if (SignUpModelView.CourseId > 0 && !string.IsNullOrEmpty(SignUpModelView.StudentName) && SignUpModelView.StudentAge > 0)
            {
                await _Sender.SendAsync(SignUpModelView);

                result = Json(new RequestResult
                {
                    State = RequestState.Success,
                    Msg   = "SignUp Process started successfully. Please check your e-mail."
                });
            }
            return(result);
        }
        public JsonResult UserSave(SignUpModelView model)
        {
            try
            {
                UserInformation user = new UserInformation
                {
                    Name = model.Name,
                    //Role = 2, // user role
                    MobileNumber = model.MobileNumber,
                    Status       = true,
                    CreatedDate  = _now,
                };
                _db.UserInformation.Add(user);
                _db.SaveChanges();

                UserLogin login = new UserLogin
                {
                    UserId        = user.Id,
                    UserName      = model.UserName,
                    Password      = model.Password,
                    IsConfirmed   = false,
                    IsLoginBefore = false,
                    IsOtpenable   = false
                };
                _db.UserLogin.Add(login);
                _db.SaveChanges();

                //Storage
                Storage storage = new Storage
                {
                    Allowed     = 5368709120,
                    UserId      = user.Id,
                    CreatedBy   = User.GetUserId(),
                    CreatedDate = _now
                };

                _db.Storage.Add(storage);
                _db.SaveChanges();

                if (login.UserName != null)
                {
                    //send confirmation email
                    string url    = string.Empty;
                    string domain = $"{HttpContext.Request.Scheme}{Uri.SchemeDelimiter}{HttpContext.Request.Host}{(HttpContext.Request.Host.HasValue ? "" : ":" + HttpContext.Request.Host.Port)}";
                    url = $"{domain}/Account/ConfirmEmail?q={ _protector.Protect(login.Id.ToString())}";
                    string body         = string.Empty;
                    string webRoothPath = _env.WebRootPath;
                    using (StreamReader reader = new StreamReader(webRoothPath + "\\Template\\E-mailTemplate.min.html"))
                    {
                        body = reader.ReadToEnd();
                    }
                    body = body.Replace("{ApplicantFullName}", user.Name)
                           .Replace("{UserName}", login.UserName)
                           .Replace("{Password}", login.Password)
                           .Replace("{Url}", url)
                           .Replace("{Year}", DateTime.UtcNow.Year.ToString());

                    string      mailAddress = model.UserName;
                    MailMessage mail        = new MailMessage();
                    SmtpClient  smtp        = new SmtpClient();

                    mail.To.Add(new MailAddress(mailAddress));
                    mail.From            = new MailAddress("*****@*****.**", "File-Koi", System.Text.Encoding.UTF8);
                    mail.Subject         = "To Confirm E-mail ";
                    mail.SubjectEncoding = System.Text.Encoding.UTF8;
                    mail.Body            = body;
                    mail.BodyEncoding    = System.Text.Encoding.UTF8;
                    mail.IsBodyHtml      = true;
                    mail.Priority        = MailPriority.High;
                    SmtpClient client = new SmtpClient
                    {
                        UseDefaultCredentials = false,
                        Credentials           = new System.Net.NetworkCredential("*****@*****.**", "45604560"),
                        Host      = "smtp.gmail.com",
                        EnableSsl = true,
                        Port      = 587,
                        Timeout   = 18000000
                    };
                    try
                    {
                        client.Send(mail);
                    }
                    catch
                    {
                        client.Port    = 25;
                        client.Timeout = 18000000;
                        try
                        {
                            client.Send(mail);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(Json("error"));
            }
            return(Json("success"));
        }