public async Task <IActionResult> NewBusiness([FromBody] User user)
        {
            BaseResult <UserModel> baseResult = new BaseResult <UserModel>();
            int userId = Convert.ToInt32(HttpContext.User.Identity.Name);

            user.creatorId = userId;
            bool isSuccess = false;
            User _user     = _SUser.CheckUser(user.email);

            if (String.IsNullOrEmpty(_user.email))
            {
                user.gender   = (int)enumGenderType.Belirtilmemiş;
                user.userGuid = Guid.NewGuid().ToString();
                string password = "";
                for (int i = 0; i < 8; i++)
                {
                    password += user.userGuid[i].ToString();
                }
                user.password   = _SMethod.StringToMd5(password);
                user.userTypeId = (int)enumUserType.business;
                user.id         = _SUser.InsertUser(user);
                if (user.id > 0)
                {
                    EmailVerificationQueueModel emailVerificationQueueModel = new EmailVerificationQueueModel()
                    {
                        email    = user.email,
                        userGuid = user.userGuid
                    };
                    PasswordQueueModel passwordQueueModel = new PasswordQueueModel()
                    {
                        email    = user.email,
                        password = password
                    };
                    await notificationDispatcher.SendEmailVerification(emailVerificationQueueModel);

                    await notificationDispatcher.SendPassword(passwordQueueModel);

                    isSuccess            = true;
                    baseResult.data.user = user;
                }
                else
                {
                    baseResult.errMessage = "Firma Oluşturulamadı!";
                }
            }
            else
            {
                baseResult.errMessage = "Bu Bilgilerde Bir Firma Zaten Mevcut";
            }
            if (isSuccess)
            {
                return(Json(baseResult));
            }
            else
            {
                baseResult.statusCode = HttpStatusCode.NotFound;
                return(new NotFoundObjectResult(baseResult));
            }
        }
        public async Task <IActionResult> ForgotPassword([FromBody] User user)
        {
            BaseResult <UserModel> baseResult = new BaseResult <UserModel>();
            bool isSuccess = false;
            User _user     = _SUser.GetByEmail(user.email);

            if (_user != null)
            {
                string guid     = Guid.NewGuid().ToString();
                string password = "";
                for (int i = 0; i < 8; i++)
                {
                    password += guid[i];
                }
                string hashedValue = _SMethod.StringToMd5(password);
                _user.password = hashedValue;
                if (_SUser.UpdateUser(_user))
                {
                    baseResult.errMessage = "Şifreniz Sıfırlandı ve E-Posta Adresinize Gönderiliyor!";
                    isSuccess             = true;
                    PasswordQueueModel passwordQueueModel = new PasswordQueueModel()
                    {
                        email    = _user.email,
                        password = password
                    };
                    await notificationDispatcher.SendPassword(passwordQueueModel);
                }
                else
                {
                    baseResult.errMessage = "Kullanıcının Şifresi Sıfırlanamadı!";
                }
            }
            else
            {
                baseResult.errMessage = "Böyle Bir Kullanıcı Bulunamadı!";
            }
            if (isSuccess)
            {
                return(Json(baseResult));
            }
            else
            {
                baseResult.statusCode = HttpStatusCode.NotFound;
                return(new NotFoundObjectResult(baseResult));
            }
        }
Example #3
0
 public async Task SendPassword(PasswordQueueModel model)
 {
     await this._hubContext.Clients.All.SendAsync("SendPassword", model);
 }
Example #4
0
        public async Task <IActionResult> ImportEventParticipants([FromForm] EventParticipant eventParticipant)
        {
            BaseResult <UserModel> baseResult          = new BaseResult <UserModel>();
            bool                        isSuccess      = false;
            List <User>                 users          = _SUser.GetAllUser();
            List <User>                 excelFileUsers = new List <User>();
            List <EventParticipant>     rels           = new List <EventParticipant>();
            Dictionary <string, string> hashedValue    = new Dictionary <string, string>();
            int id = Convert.ToInt32(HttpContext.User.Identity.Name);

            using (MemoryStream ms = new MemoryStream())
            {
                IFormFile formFile = eventParticipant.importUserFile[0];
                await formFile.CopyToAsync(ms);

                using (ExcelPackage excelPackage = new ExcelPackage(ms))
                {
                    var workSheet  = excelPackage.Workbook.Worksheets.First();
                    int rowCount   = workSheet.Dimension.End.Row;
                    int userTypeId = Convert.ToInt32(_SMethod.GetEnumValue(enumUserType.user));
                    for (int row = 1; row <= rowCount; row++)
                    {
                        var emailAddress = workSheet.Cells[row, 1].Value;
                        if (emailAddress != null)
                        {
                            bool emailVerification = _SMethod.ValidateEmail(emailAddress.ToString());
                            if (emailVerification)
                            {
                                User   _user     = new User();
                                string guid      = Guid.NewGuid().ToString();
                                string _password = "";
                                for (int i = 0; i < 8; i++)
                                {
                                    _password += guid[i];
                                }

                                _user.email              = emailAddress.ToString();
                                _user.name               = _user.surname = "";
                                _user.avatarPath         = "";
                                _user.phoneNr            = _user.taxNr = "";
                                _user.userTypeId         = userTypeId;
                                _user.userGuid           = Guid.NewGuid().ToString();
                                _user.identityNr         = "";
                                _user.password           = _SMethod.StringToMd5(_password);
                                _user.emailVerification  = 1;
                                _user.profileStatus      = 1;
                                _user.notificationStatus = 2;
                                _user.statusId           = 2;
                                _user.creationDate       = _user.birthDate = DateTime.Now;
                                _user.gender             = Convert.ToInt32(_SMethod.GetEnumValue(enumGenderType.Belirtilmemiş));
                                if (excelFileUsers.FirstOrDefault(x => x.email.Equals(emailAddress)) == null)
                                {
                                    excelFileUsers.Add(_user);
                                    hashedValue.TryAdd(emailAddress.ToString(), _password);
                                }
                            }
                        }
                    }
                    List <User> usersNotIn = excelFileUsers.Where(x => !users.Any(y => y.email.Equals(x.email))).ToList();
                    foreach (var item in usersNotIn)
                    {
                        int userId = _SUser.InsertUser(item);
                        rels.Add(new EventParticipant
                        {
                            eventId      = eventParticipant.eventId,
                            userId       = userId,
                            creatorId    = id,
                            creationDate = DateTime.Now,
                            statusId     = 2
                        });
                        string _password = "";
                        hashedValue.TryGetValue(item.email, out _password);
                        if (!String.IsNullOrEmpty(_password))
                        {
                            EmailVerificationQueueModel emailVerificationQueueModel = new EmailVerificationQueueModel()
                            {
                                email    = item.email,
                                userGuid = item.userGuid
                            };
                            PasswordQueueModel passwordQueue = new PasswordQueueModel()
                            {
                                email    = item.email,
                                password = _password
                            };
                            await notificationDispatcher.SendPassword(passwordQueue);

                            await notificationDispatcher.SendEmailVerification(emailVerificationQueueModel);
                        }
                    }
                    List <User> usersIn = excelFileUsers.Where(x => users.Any(y => y.email.Equals(x.email))).ToList();
                    foreach (var item in usersIn)
                    {
                        rels.Add(new EventParticipant
                        {
                            eventId      = eventParticipant.eventId,
                            userId       = item.id,
                            creatorId    = id,
                            creationDate = DateTime.Now,
                            statusId     = 2
                        });
                    }
                    List <User> participants = new List <User>();
                    participants.AddRange(usersNotIn);
                    participants.AddRange(usersIn);
                    isSuccess             = _SEventParticipant.BulkInsertParticipants(rels);
                    baseResult.data.users = participants;
                }
            }
            if (isSuccess)
            {
                return(Json(baseResult));
            }
            else
            {
                baseResult.statusCode = HttpStatusCode.NotFound;
                return(new NotFoundObjectResult(baseResult));
            }
        }