Beispiel #1
0
        public CuratorMethodicsGroup CreateCuratorMethodicsGroup(long curatorId, CuratorMethodicsGroup methodicsGroup)
        {
            using (var methodicsGroupsRepository = new BaseRepository<CuratorMethodicsGroup>())
            {
                Client curator = methodicsGroupsRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
                if (curator == null)
                {
                    throw new UserDoesNotExistException();
                }

                if (String.IsNullOrWhiteSpace(methodicsGroup.Name))
                {
                    throw new RequireFieldException();
                }

                if (methodicsGroupsRepository.GetAllItems.Any(x => String.Equals(x.Name, methodicsGroup.Name) && x.Curator.Id == curatorId))
                {
                    throw new MethodicsGroupNameException();
                }

                methodicsGroup.Curator = curator;

                if (!methodicsGroupsRepository.Create(methodicsGroup).Status)
                {
                    throw new CreateException();
                }

                return methodicsGroup;
            }
        }
Beispiel #2
0
        public void UpdateCuratorMethodicsGroup(long curatorId, long methodicsGroupId, CuratorMethodicsGroup methodicsGroup)
        {
            using (var methodicsGroupsRepository = new BaseRepository<CuratorMethodicsGroup>())
            {
                Client curator = methodicsGroupsRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
                if (curator == null)
                {
                    throw new UserDoesNotExistException();
                }

                CuratorMethodicsGroup foundedMethodicsGroup =
                    methodicsGroupsRepository.GetAllItems.FirstOrDefault(
                        x => x.Id == methodicsGroupId && x.Curator.Id == curatorId);

                if (foundedMethodicsGroup == null)
                {
                    throw new MethodicsGroupDoesNotExistException();
                }

                if (methodicsGroup.Name != null)
                {
                    if (String.IsNullOrWhiteSpace(methodicsGroup.Name))
                    {
                        throw new RequireFieldException();
                    }

                    // Check unique Name
                    // SELECT Name FROM CuratorMethodicsGroups WHERE Name = methodics.Name AND Curator_Id = methodics.Curator.Id
                    if (!String.Equals(methodicsGroup.Name, foundedMethodicsGroup.Name) &&
                        methodicsGroupsRepository.GetAllItems.Any(x => String.Equals(x.Name, methodicsGroup.Name) && x.Curator.Id == curatorId))
                    {
                        throw new MethodicsGroupNameException();
                    }

                    foundedMethodicsGroup.Name = methodicsGroup.Name;
                }

                if (!methodicsGroupsRepository.Update(foundedMethodicsGroup).Status)
                {
                    throw new UpdateException();
                }

            }
        }