Example #1
0
        /// <summary>
        /// Снимает метку "delete" пользователя с <paramref name="id"/> устанавливает статус System;
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ServiceResponce MarkNotDeleted(int id)
        {
            User user = _userRep.FindOneById(id);

            if (user == null)
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "user doesn't exist"));
            }

            if (!StatusService.CanChangeStatus(user, UserStatusType.MarkDeleted, true))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "the user isn't deleted"));
            }

            if (_userRep.CountByCredentails(user.UserName, user.UserPhone) != 0)
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "user with such email or phone already exists"));
            }

            StatusService.ChangeStatus(user, UserStatusType.System);
            _userRep.Save(user);
            return(ServiceResponce.FromSuccess());
        }
Example #2
0
        /// <summary>
        /// Посылает приглашение на регистрацию указанному пользователю
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ServiceResponce SendInvite(SendInviteModel model)
        {
            if (UserRep.CountByCredentails(model.Email, null) != 0)
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "User with Email " + model.Email + " already exist in system"));
            }
            InviteCode Invite = SendInviteModelHelper.CreateInviteCode(model);

            if (InviteRep.Add(Invite))
            {
                // Создаем задачу отправки сообщения в фоне и запускаем ее
                new Thread(send =>
                {
                    InviteEmailModel InviteEmailModel = InviteEmailModelHelper.GetInviteEmailModel(Invite);
                    string inviteText = TemplateServ
                                        .Run("Emails/Invite", typeof(InviteEmailModel), InviteEmailModel);
                    if (!EmailService.SendMail(InviteEmailModel, inviteText))
                    {
                        StatusService.ChangeStatus(Invite.User, UserStatusType.Invite, null, "Invite Email was not delivered");
                    }
                    else
                    {
                        StatusService.ChangeStatus(Invite.User, UserStatusType.Invite, null, "Invite Email was delivered");
                    }
                    InviteRep.Update(Invite);
                }).Start();

                return(ServiceResponce
                       .FromSuccess()
                       .Result("invite for user sended"));
            }
            else
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "error saving invited user in DB"));
            }
        }
Example #3
0
        /// <summary>
        /// Меняет статус Locked пользователя с <paramref name="id"> </paramref>на System;
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ServiceResponce Unlock(int id)
        {
            User user = _userRep.FindOneById(id);

            if (user == null)
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "User with specified Id was not found"));
            }

            if (!StatusService.CanChangeStatus(user, UserStatusType.Locked, true))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "it is impossible to unlock because the user isn't locked"));
            }
            StatusService.ChangeStatus(user, UserStatusType.System);
            _userRep.Save(user);

            return(ServiceResponce.FromSuccess());
        }
Example #4
0
        /// <summary>
        /// Помечает пользователя с <paramref name="id"/> как удаленного;
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ServiceResponce MarkDeleted(int id)
        {
            User user = _userRep.FindOneById(id);

            if (user == null)
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "Can't delete user because he doesn't exist"));
            }

            if (!StatusService.CanChangeStatus(user, UserStatusType.MarkDeleted))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "it isn't possible to change the status to deleted"));
            }

            StatusService.ChangeStatus(user, UserStatusType.MarkDeleted);
            _userRep.Save(user);

            return(ServiceResponce.FromSuccess());
        }
Example #5
0
        /// <summary>
        /// Обновляет данные приглашения пользователя
        /// и переводит статус приглашения в статус ожидающий
        /// "Акцепта(ТЗ стр.8)"
        /// </summary>
        /// <param name="code">Код приглашения</param>
        /// <param name="model">Модель с данными для обновления</param>
        /// <returns></returns>
        public ServiceResponce UpdateInvite(string code, UpdateInviteModel model)
        {
            InviteCode invite = InviteRep.FindOneByCode(code);

            if (invite == null)
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "invite not found"));
            }

            User user = UserRep.FindOneById(invite.User.Id);

            if (!StatusService.CanChangeStatus(user, UserStatusType.AcceptInvite))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "it isn't possible to change the status to AcceptInvited"));
            }


            if (!UserService.CanUpdateUserCredentails(user.Id, model.Email, model.Phone, UserRep))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "user with such Email or Phone already exists"));
            }

            if (!model.GeneratePassword && !PasswordService.IsPasswordAcceptable(model.Password))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "Password not acceptable"));
            }

            // Генерируем и хэшируем пароль
            string Password = model.Password;

            if (model.GeneratePassword)
            {
                Password = PasswordService.GeneratePasswordString();
            }
            model.Password = PasswordService.GeneratePasswordHash(Password);

            user = UpdateInviteModelHelper.UpdateInviteUser(user, model);



            UserRep.Save(user);
            InviteRep.Delete(invite.Id);

            ServiceResponce response = ServiceResponce
                                       .FromSuccess()
                                       .Result("invite accepted");

            if (model.GeneratePassword)
            {
                response.Add("GeneratedPassword", Password);
            }
            return(response);
        }