Example #1
0
        /// <see cref="IPersonService.DeleteFacts"/>
        public ServiceResponce DeleteFacts(IEnumerable <PersonFactModel> models)
        {
            if (models.Any(item => !_personRepository.DeletePersonFact(item.Id)))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Result($"Error delete fact"));
            }

            return(ServiceResponce
                   .FromSuccess()
                   .Result("Facts delete complete"));
        }
Example #2
0
        /// <see cref="IConcertService.SaveConcertProgramm(ConcertProgrammModel)"/>
        public ServiceResponce SaveConcertProgramm(ConcertProgrammModel model)
        {
            var succes = ServiceResponce.FromSuccess().Result("Concert programm save complete");
            var error  = ServiceResponce.FromFailed().Result($"Error save concert programm");
            var res    = _concertRepository.AddConcertProgramm(
                ConcertModelHelper.GetProgramm(model));

            if (res != null)
            {
                succes.Add("ProgrammId", res.Id);
            }
            return(res != null ? succes : error);
        }
Example #3
0
        /// <summary>
        /// Удалить список описаний
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public ServiceResponce DeleteDescriptions(IEnumerable <EventDescriptionModel> models)
        {
            if (models.Any(item => !_eventRepository.DeleteDescription(item.Id)))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Result($"Error delete description"));
            }

            return(ServiceResponce
                   .FromSuccess()
                   .Result("Descriptions delete complete"));
        }
Example #4
0
        /// <see cref="IEventService.DeleteFactTypes"/>
        public ServiceResponce DeleteFactTypes(IEnumerable <EventFactTypeModel> models)
        {
            if (models.Any(item => !_eventRepository.DeleteFactType(item.Id)))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Result($"Error delete fact type"));
            }

            return(ServiceResponce
                   .FromSuccess()
                   .Result("Fact type delete complete"));
        }
Example #5
0
        /// <summary>
        /// Удалить список медиа
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public ServiceResponce DeleteMedia(IEnumerable <EventMediaModel> models)
        {
            if (models.Any(item => !_eventRepository.DeleteMedia(item.Id)))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Result($"Error delete media"));
            }

            return(ServiceResponce
                   .FromSuccess()
                   .Result("Media delete complete"));
        }
Example #6
0
        /// <summary>
        /// Удалить ссылки
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public ServiceResponce DeleteSocialLink(IEnumerable <PersonSocialLinkModel> models)
        {
            if (models.Any(item => !_personRepository.DeleteSocialLink(item.Id)))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Result($"Error delete SocialLink"));
            }

            return(ServiceResponce
                   .FromSuccess()
                   .Result("SocialLink delete complete"));
        }
Example #7
0
        /// <summary>
        /// Удалить типы медиа
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public ServiceResponce DeleteMediaTypes(IEnumerable <MediaTypeModel> models)
        {
            if (models.Any(item => !_personRepository.DeleteMediaType(item.Id)))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Result($"Error delete media type"));
            }

            return(ServiceResponce
                   .FromSuccess()
                   .Result("Media type delete complete"));
        }
Example #8
0
        /// <summary>
        /// Удалить связи
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public ServiceResponce DeleteConnection(IEnumerable <EventConnectionModel> models)
        {
            var result = _eventRepository.DeleteConnections(models.Select(o => new EventConnection
            {
                Id = o.Id
            }).ToList());

            return(result ? ServiceResponce
                   .FromSuccess()
                   .Result("Connections delete complete") :
                   ServiceResponce
                   .FromFailed()
                   .Result($"Error delete connections"));
        }
Example #9
0
        /// <see cref="IConcertService.SaveGroup"/>
        public ServiceResponce SaveGroup(ActorGroupModel model)
        {
            var res      = _concertRepository.SaveGroup(ConcertModelHelper.GetActorGroup(model));
            var response = res != null?ServiceResponce
                           .FromSuccess()
                           .Result("Actor group save") :
                               ServiceResponce
                               .FromFailed()
                               .Result("Error save actor group");

            if (res != null)
            {
                response.Add("GroupId", res.Id);
            }
            return(response);
        }
Example #10
0
 /// <summary>
 /// Добавить/Изменить имена антропометрических характеристик
 /// </summary>
 /// <param name="models"></param>
 /// <returns></returns>
 /// <exception cref="NotImplementedException"></exception>
 public ServiceResponce UpdateAntroNames(IEnumerable <PersonAntroNameModel> models)
 {
     foreach (var item in models)
     {
         var name = _personRepository.UpdateAntroName(new PersonAntroName {
             Id = item.Id, Name = item.Name
         });
         if (name == null)
         {
             return(ServiceResponce.FromFailed().Result($"Error add {item.Name}"));
         }
     }
     return(ServiceResponce
            .FromSuccess()
            .Result("Antro names save complete"));
 }
Example #11
0
        /// <summary>
        /// Удалить антропометрические характеристики
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public ServiceResponce DeleteAntros(IEnumerable <PersonAntroModel> models)
        {
            var result = _personRepository.DeletePersonAntros(models.Select(o => new PersonAntro
            {
                Id        = o.Id,
                id_Antro  = o.IdAntro,
                id_Person = o.IdPerson,
                Value     = o.Value
            }).ToList());

            return(result ? ServiceResponce
                   .FromSuccess()
                   .Result("Antros delete complete") :
                   ServiceResponce
                   .FromFailed()
                   .Result($"Error delete antros"));
        }
Example #12
0
        /// <summary>
        /// Удалить связи
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public ServiceResponce DeleteConnection(IEnumerable <PersonConnectionModel> models)
        {
            var result = _personRepository.DeleteConnections(models.Select(o => new PersonConnection
            {
                Id                 = o.Id,
                id_Person          = o.id_Person,
                id_ConnectionType  = o.id_ConnectionType,
                id_Event           = o.id_Event,
                id_PersonConnectTo = o.id_PersonConnectTo
            }).ToList());

            return(result ? ServiceResponce
                   .FromSuccess()
                   .Result("Connections delete complete") :
                   ServiceResponce
                   .FromFailed()
                   .Result($"Error delete connections"));
        }
Example #13
0
        /// <summary>
        /// Добавить/обновить антропометрические характеристики для Person c Id = <paramref name="pesonId"/>
        /// </summary>
        /// <param name="pesonId"></param>
        /// <param name="models"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public ServiceResponce UpdateAntros(int pesonId, IEnumerable <PersonAntroModel> models, int userId)
        {
            var result = _personRepository.AddPersonAntros(
                models.Select(o => new PersonAntro
            {
                Id        = o.Id,
                id_Antro  = o.IdAntro,
                id_Person = pesonId,
                Value     = o.Value
            }).ToList(), userId);

            return(result ? ServiceResponce
                   .FromSuccess()
                   .Result("Antros save complete") :
                   ServiceResponce
                   .FromFailed()
                   .Result($"Error save antros"));
        }
Example #14
0
        /// <summary>
        /// Добавить/Изменить типы описаний
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public ServiceResponce UpdateDescriptionTypes(IEnumerable <PersonDescriptionTypeModel> models)
        {
            foreach (var item in models)
            {
                var result = _eventRepository.UpdateDescriptionType(new PersonDescriptionType {
                    Id = item.Id, Name = item.Name
                });
                if (result == null)
                {
                    return(ServiceResponce
                           .FromFailed()
                           .Result($"Error save description type"));
                }
            }

            return(ServiceResponce
                   .FromSuccess()
                   .Result("Description type save complete"));
        }
Example #15
0
        /// <see cref="IPersonService.UpdateFactTypes"/>
        public ServiceResponce UpdateFactTypes(IEnumerable <PersonFactTypeModel> models)
        {
            foreach (var item in models)
            {
                var result = _personRepository.UpdateFactType(new PersonFactType {
                    Id = item.Id, Name = item.Name
                });
                if (result == null)
                {
                    return(ServiceResponce
                           .FromFailed()
                           .Result($"Error save fact type"));
                }
            }

            return(ServiceResponce
                   .FromSuccess()
                   .Result("Fatc type save complete"));
        }
Example #16
0
        /// <summary>
        /// Изменение пароля пользователя с идентификатором <paramref name="id" />
        /// пользователем с Email <paramref name="currentUserEmail" />;
        /// В случае если пользователь меняет пароль самому себе он должен указать старый пароль
        /// </summary>
        /// <param name="id">Идентификатор пользователя для которого меняется пароль</param>
        /// <param name="currentUserEmail">Email польозователя который меняет пароль</param>
        /// <param name="model"></param>
        /// <returns></returns>
        public ServiceResponce ChangePassword(int id, string currentUserEmail, ChangePasswordModel model)
        {
            User user = _userRep.FindOneById(id);

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

            bool SelfChangePassword = false;

            if (user.UserName.Equals(currentUserEmail))
            {
                SelfChangePassword = true;
                if (!user.Password.Equals(PasswordService.GeneratePasswordHash(model.OldPassword)))
                {
                    return(ServiceResponce
                           .FromFailed()
                           .Add("error", "Incorrect OldPassword"));
                }
            }

            user.Password = PasswordService.GeneratePasswordHash(model.NewPassword);
            _userRep.Save(user);

            if (model.SendCopyPassword)
            {
                // Создаем задачу отправки сообщения в фоне и запускаем ее
                new Thread(send =>
                {
                    ChangePasswordEmailModel ChangePasswordEmailModel
                        = ChangePasswordEmailModelHelper.GetChangePasswordEmailModel(user.UserName, model.NewPassword, SelfChangePassword);
                    string ChangePasswordText = _templateServ
                                                .Run("Emails/ChangePassword", typeof(ChangePasswordEmailModel), ChangePasswordEmailModel);
                    EmailService.SendMail(ChangePasswordEmailModel, ChangePasswordText);
                }).Start();
            }

            return(ServiceResponce.FromSuccess());
        }
Example #17
0
        /// <summary>
        /// Обновляет уже существующего пользователя
        /// </summary>
        /// <param name="id"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public ServiceResponce UpdateUser(int id, UpdateUserModel model)
        {
            User user = _userRep.FindOneById(id);

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

            user = UpdateUserModelHelper.UpdateUser(user, model);

            if (!CanUpdateUserCredentails(user.Id, model.Email, model.Phone, _userRep))
            {
                return(ServiceResponce.FromFailed().Add("error", "Can't update to specified email or phone"));
            }
            _userRep.Save(user);
            return(ServiceResponce.FromSuccess());
        }
Example #18
0
        /// <summary>
        /// Добавить/Изменить ссылки для Person c Id = <paramref name="pesonId"/>
        /// </summary>
        /// <param name="pesonId"></param>
        /// <param name="models"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public ServiceResponce UpdateSocialLink(int pesonId, IEnumerable <PersonSocialLinkModel> models, int userId)
        {
            var result = _personRepository.UpdateSocialLinks(
                models.Select(o => new PersonSocialLink
            {
                Id                = o.Id,
                id_Person         = pesonId,
                id_SocialLinkType = o.IdSocialLinkType,
                Link              = o.Link,
                Description       = o.Description,
                Destination       = (DestinationTypes)o.Destination
            }).ToList(), userId);

            return(result ? ServiceResponce
                   .FromSuccess()
                   .Result("SocialLink save complete") :
                   ServiceResponce
                   .FromFailed()
                   .Result($"Error save SocialLink"));
        }
Example #19
0
        /// <summary>
        /// Добавить/Изменить список описаний для Person c Id = <paramref name="pesonId"/>
        /// </summary>
        /// <param name="pesonId"></param>
        /// <param name="models"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public ServiceResponce UpdateDescriptions(int pesonId, IEnumerable <PersonDescriptionModel> models, int userId)
        {
            if (models == null || models.Select(item => _personRepository.UpdateDescription(new PersonDescription
            {
                Id = item.Id,
                id_Person = pesonId,
                id_DescriptionType = item.id_DescriptionType,
                DescriptionText = item.DescriptionText,
                Status = item.Status
            }, userId)).Any(result => result == null))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Result($"Error save description"));
            }

            return(ServiceResponce
                   .FromSuccess()
                   .Result("Descriptions save complete"));
        }
Example #20
0
        /// <summary>
        /// Добавить/Изменить связи для Person c Id = <paramref name="pesonId"/>
        /// </summary>
        /// <param name="pesonId"></param>
        /// <param name="models"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public ServiceResponce UpdateConnection(int pesonId, IEnumerable <PersonConnectionModel> models, int userId)
        {
            var result = _personRepository.AddConnections(
                models.Select(o => new PersonConnection
            {
                Id                 = o.Id,
                id_Person          = pesonId,
                id_ConnectionType  = o.id_ConnectionType,
                id_Event           = o.id_Event,
                id_PersonConnectTo = o.id_PersonConnectTo,
                Description        = o.Description
            }).ToList(), userId);

            return(result ? ServiceResponce
                   .FromSuccess()
                   .Result("Connections save complete") :
                   ServiceResponce
                   .FromFailed()
                   .Result($"Error save connections"));
        }
Example #21
0
        /// <see cref="IPersonService.UpdateFacts(int, IEnumerable{PersonFactModel}, int)"/>
        public ServiceResponce UpdateFacts(int pesonId, IEnumerable <PersonFactModel> models, int userId)
        {
            if (models.Select(item => _personRepository.UpdatePersonFact(new PersonFact
            {
                Id = item.Id,
                id_Person = pesonId,
                id_FactType = item.id_FactType,
                FactText = item.FactText,
                Status = item.Status,
                Source = item.Source
            }, userId)).Any(result => result == null))
            {
                return(ServiceResponce
                       .FromFailed()
                       .Result($"Error save fact"));
            }

            return(ServiceResponce
                   .FromSuccess()
                   .Result("Facts save complete"));
        }
Example #22
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 #23
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 #24
0
        /// <summary>
        /// Проверяет есть ли активный, непринятый инвайт по коду,
        /// Если есть: возвращает Email приглашенного пользователя для использования при обновлении информации;
        /// Если он есть но просрочен: удаляет приглашенного пользователя и инвайт для него;
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public ServiceResponce CheckInviteExist(string code)
        {
            InviteCode invite = InviteRep.FindOneByCode(code);

            if (invite == null)
            {
                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "Invite for this code do not exist"));
            }
            if (invite.ActiveTo < DateTime.Now)
            {
                this.DeleteInviteAndUser(invite);

                return(ServiceResponce
                       .FromFailed()
                       .Add("error", "Invite is out of date and will be removed"));
            }
            return(ServiceResponce
                   .FromSuccess()
                   .Result("Founded")
                   .Add("Email", invite.User.UserName));
        }
Example #25
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 #26
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);
        }
Example #27
0
        /// <summary>
        /// Сервис успешно выполнил свою работу
        /// </summary>
        /// <returns></returns>
        public static ServiceResponce FromSuccess()
        {
            ServiceResponce ServiceResponce = new ServiceResponce();

            return(ServiceResponce.Status("success"));
        }
Example #28
0
        /// <summary>
        /// Сервис завершил свою работу с ошибками
        /// </summary>
        /// <returns></returns>
        public static ServiceResponce FromFailed()
        {
            ServiceResponce ServiceResponce = new ServiceResponce();

            return(ServiceResponce.Status("failed"));
        }