Beispiel #1
0
        public override async Task <ErrorRepsonse <RegionDto> > Update(UpdateRegionDto updateDto)
        {
            var region = await _repository.GetById(updateDto.Id);

            var similar = await _repository.Any(c => c.CountryId == region.CountryId && c.Name == updateDto.Name && c.Id != updateDto.Id);

            if (similar)
            {
                return(new ErrorRepsonse <RegionDto>()
                {
                    Errors = new List <string>()
                    {
                        "Region.Exsist"
                    }
                });
            }

            region.Name = updateDto.Name;
            await _repository.Update(region);

            var response = new ErrorRepsonse <RegionDto>(_mapper.Map <RegionDto>(region));

            if (!response.Errors.Any())
            {
                RemoveCash();
            }
            return(response);
        }
        public override async Task <ErrorRepsonse <GroupDto> > AddAsync(CreateGroupDto createDto)
        {
            createDto.Name = createDto.Name.Trim();
            var similar = await _repository.Any(c => c.Name == createDto.Name);

            var response = new ErrorRepsonse <GroupDto>();

            if (similar)
            {
                response.Errors.Add("Similar");
            }
            else
            if (createDto.PrivilegesId?.Any() != true)
            {
                response.Errors.Add("Privileges is required");
            }
            else
            {
                var group = _mapper.Map <Group>(createDto);
                await _repository.AddAsync(group);

                var dto = _mapper.Map <GroupDto>(group);
                response.Data = dto;
            }
            return(response);
        }
        public async Task <ErrorRepsonse <PhoneDto> > AddPhone(AddPhoneDto addPhoneDto)
        {
            var client = await _repository.GetById(addPhoneDto.objectId);

            var response = new ErrorRepsonse <PhoneDto>();

            if (client == null)
            {
                response.Errors.Add("Not.Found");
                return(response);
            }
            await _repository.LoadCollection(client, c => c.ClientPhones);

            if (client.ClientPhones.Any(c => c.Phone == addPhoneDto.Phone))
            {
                response.Errors.Add("Dublicate");
                return(response);
            }
            var clientPhone = new ClientPhone()
            {
                ClientId = client.Id,
                Phone    = addPhoneDto.Phone
            };

            client.ClientPhones.Add(clientPhone);
            await _repository.Update(client);

            response.Data = _mapper.Map <PhoneDto>(clientPhone);
            RemoveCash();
            return(response);
        }
        public override async Task <ErrorRepsonse <CountryDto> > AddAsync(CreateCountryDto createDto)
        {
            var response = new ErrorRepsonse <CountryDto>();
            var similer  = await _repository.FirstOrDefualt(c => c.Name == createDto.Name);

            if (similer != null)
            {
                response.Errors.Add("Country.Similar");
                return(response);
            }
            var country = _mapper.Map <Country>(createDto);

            if (!(await _repository.Any()))
            {
                country.IsMain = true;
            }

            await _repository.AddAsync(country);

            if (country.MediatorId != null)
            {
                await _repository.LoadRefernces(country, c => c.Mediator);
            }
            response = new ErrorRepsonse <CountryDto>(_mapper.Map <CountryDto>(country));
            RemoveCash();
            return(response);
        }
        public override async Task <ErrorRepsonse <OutComeTypeDto> > Delete(int id)
        {
            var enrity = await _repository.GetById(id);

            var response = new ErrorRepsonse <OutComeTypeDto>();

            if (enrity == null)
            {
                response.NotFound = true;
                response.Errors.Add("Not.Found");
            }
            else
            {
                if (await _outcomeRepository.Any(c => c.OutComeTypeId == id))
                {
                    response.CantDelete = true;
                    response.Errors.Add("Cant.Delete");
                }
                else
                {
                    await _repository.Delete(enrity);

                    response.Data = _mapper.Map <OutComeTypeDto>(enrity);
                }
            }
            return(response);
        }
Beispiel #6
0
        public virtual async Task <ErrorRepsonse <TDTO> > Update(UpdateDto updateDto)
        {
            var entity = _mapper.Map <TEntity>(updateDto);
            await _repository.Update(entity);

            var response = new ErrorRepsonse <TDTO>(_mapper.Map <TDTO>(entity));

            return(response);
        }
Beispiel #7
0
        public virtual async Task <ErrorRepsonse <TDTO> > AddAsync(CreateDto createDto)
        {
            var entity = _mapper.Map <TEntity>(createDto);
            await _repository.AddAsync(entity);

            var response = new ErrorRepsonse <TDTO>(_mapper.Map <TDTO>(entity));

            return(response);
        }
        public override async Task <ErrorRepsonse <ClientDto> > Delete(int id)
        {
            var response = new ErrorRepsonse <ClientDto>();

            if (await _orderRepository.Any(c => c.ClientId == id))
            {
                response.Errors.Add("Cann't delete");
                return(response);
            }
            return(await base.Delete(id));
        }
Beispiel #9
0
        public virtual async Task <ErrorRepsonse <TDTO> > Delete(int id)
        {
            var response = new ErrorRepsonse <TDTO>();
            var entity   = await _repository.GetById(id);

            if (entity == null)
            {
                response.Errors.Add("Not.Found");
                return(response);
            }
            await _repository.Delete(entity);

            response.Data = _mapper.Map <TDTO>(entity);
            return(response);
        }
Beispiel #10
0
        public override async Task <ErrorRepsonse <UserDto> > Update(UpdateUserDto updateDto)
        {
            var user = await _repository.GetById(updateDto.Id);

            await _repository.LoadCollection(user, c => c.AgentCountrs);

            bool requeirdReacsh    = user.CanWorkAsAgent == true ? true : updateDto.CanWorkAsAgent != user.CanWorkAsAgent;
            var  similerUserByname = await _repository.Any(c => c.Name.ToLower() == updateDto.Name.ToLower() && c.Id != updateDto.Id);

            if (similerUserByname)
            {
                return(new ErrorRepsonse <UserDto>()
                {
                    Errors = new List <string>()
                    {
                        "Employee.Exisit"
                    }
                });
            }
            updateDto.UserName = updateDto.UserName.Trim();
            if (!String.IsNullOrWhiteSpace(updateDto.UserName))
            {
                var similerUserByUserName = await _repository.Any(c => c.UserName.ToLower() == updateDto.UserName.ToLower() && c.Id != updateDto.Id);

                if (similerUserByUserName)
                {
                    return(new ErrorRepsonse <UserDto>()
                    {
                        Errors = new List <string>()
                        {
                            "Employee.Exisit"
                        }
                    });
                }
            }

            user.AgentCountrs.Clear();
            _mapper.Map <UpdateUserDto, User>(updateDto, user);
            await _repository.Update(user);

            if (requeirdReacsh)
            {
                RemoveCash();
            }
            var response = new ErrorRepsonse <UserDto>(_mapper.Map <UserDto>(await GetById(user.Id)));

            return(response);
        }
        public override async Task <ErrorRepsonse <CountryDto> > Update(UpdateCountryDto updateDto)
        {
            var similar = await _repository.Any(c => c.Name == updateDto.Name && c.Id != updateDto.Id);

            var response = new ErrorRepsonse <CountryDto>();

            if (similar)
            {
                response.Errors.Add("There.Is.Similar.Country");
                return(response);
            }

            response = await base.Update(updateDto);

            return(response);
        }
        public override async Task <ErrorRepsonse <ClientDto> > AddAsync(CreateClientDto createDto)
        {
            var response = new ErrorRepsonse <ClientDto>();

            if (await _repository.Any(c => c.UserName.ToLower() == createDto.UserName || c.Name.ToLower() == createDto.Name.ToLower()))
            {
                response.Errors.Add("Exisit");
                return(response);
            }
            var client = _mapper.Map <Client>(createDto);
            await _repository.AddAsync(client);

            client = await _repository.GetById(client.Id);

            RemoveCash();
            return(new ErrorRepsonse <ClientDto>(_mapper.Map <ClientDto>(client)));
        }
Beispiel #13
0
        public override async Task <ErrorRepsonse <UserDto> > Delete(int id)
        {
            var user = await _repository.GetById(id);

            if (user == null)
            {
                return new ErrorRepsonse <UserDto>()
                       {
                           Errors = new List <string>()
                           {
                               "Not.Found"
                           }
                       }
            }
            ;
            var canntDelete = new ErrorRepsonse <UserDto>(_mapper.Map <UserDto>(user));

            canntDelete.Errors.Add("Cannt.Delete");

            await _repository.LoadCollection(user, c => c.Incomes);

            if (user.Incomes.Any())
            {
                return(canntDelete);
            }
            await _repository.LoadCollection(user, c => c.OutComes);

            if (user.OutComes.Any())
            {
                return(canntDelete);
            }
            await _repository.LoadCollection(user, c => c.Clients);

            if (user.Clients.Any())
            {
                return(canntDelete);
            }
            if (await _orderRepository.Any(c => c.AgentId == user.Id))
            {
                return(canntDelete);
            }

            return(await base.Delete(id));
        }
        public override async Task <ErrorRepsonse <CountryDto> > Delete(int id)
        {
            var country = await _repository.GetById(id);

            await _repository.LoadCollection(country, c => c.Clients);

            await _repository.LoadCollection(country, c => c.AgentCountrs);

            var response = new ErrorRepsonse <CountryDto>();

            if (country.AgentCountrs.Any() || country.Clients.Any())
            {
                response.Errors.Add("Cant.Delete");
                return(response);
            }
            response = await base.Delete(id);

            return(response);
        }
Beispiel #15
0
        public override async Task <ErrorRepsonse <RegionDto> > AddAsync(CreateRegionDto createDto)
        {
            var response = new ErrorRepsonse <RegionDto>();
            var similar  = await _repository.Any(c => c.Name == createDto.Name && c.CountryId == createDto.CountryId);

            if (similar)
            {
                response.Errors.Add("Region.Exisit");
                return(response);
            }
            var entity = _mapper.Map <Region>(createDto);
            await _repository.AddAsync(entity);

            await _repository.LoadRefernces(entity, c => c.Country);

            response = new ErrorRepsonse <RegionDto>(_mapper.Map <RegionDto>(entity));
            RemoveCash();
            return(response);
        }
        public override async Task <ErrorRepsonse <TDTO> > AddAsync(CreateDto createDto)
        {
            var similar = await _repository.Any(c => c.Name == createDto.Name);

            var response = new ErrorRepsonse <TDTO>();

            if (similar == true)
            {
                response.Errors.Add("Similar");
            }
            else
            {
                var entity = _mapper.Map <TEntity>(createDto);
                await _repository.AddAsync(entity);

                var dto = _mapper.Map <TDTO>(entity);
                response.Data = dto;
            }
            return(response);
        }
        public override async Task <ErrorRepsonse <TDTO> > Update(UpdateDto updateDto)
        {
            var similar = await _repository.Any(c => c.Id != updateDto.Id && c.Name == updateDto.Name);

            var response = new ErrorRepsonse <TDTO>();

            if (similar == true)
            {
                response.Errors.Add("Similar");
            }
            else
            {
                var entity = await _repository.GetById(updateDto.Id);

                _mapper.Map(updateDto, entity);
                await _repository.Update(entity);

                response.Data = _mapper.Map <TDTO>(entity);
            }
            return(response);
        }
Beispiel #18
0
        public override async Task <ErrorRepsonse <GroupDto> > Update(UpdateGroupDto updateDto)
        {
            var similar = await _repository.Any(c => c.Id != updateDto.Id && c.Name == updateDto.Name);

            var response = new ErrorRepsonse <GroupDto>();

            if (similar)
            {
                response.Errors.Add("Similar");
            }
            else
            {
                var group = await _repository.FirstOrDefualt(c => c.Id == updateDto.Id);

                if (group == null)
                {
                    response.NotFound = true;
                }
                else
                {
                    group.Name = updateDto.Name;
                    await _repository.LoadCollection(group, c => c.GroupPrivileges);

                    group.GroupPrivileges = group.GroupPrivileges.Where(c => updateDto.Privileges.Contains(c.PrivilegId)).ToList();
                    var newPrivlieges = updateDto.Privileges.Except(group.GroupPrivileges.Select(c => c.PrivilegId));
                    foreach (var item in newPrivlieges)
                    {
                        group.GroupPrivileges.Add(new GroupPrivilege()
                        {
                            GroupId = group.Id, PrivilegId = item
                        });
                    }
                    await _repository.Update(group);

                    response.Data = _mapper.Map <GroupDto>(group);
                }
            }
            return(response);
        }
Beispiel #19
0
        public override async Task <ErrorRepsonse <GroupDto> > Delete(int id)
        {
            var group    = (await _repository.GetAsync(c => c.Id == id, c => c.GroupPrivileges)).FirstOrDefault();
            var response = new ErrorRepsonse <GroupDto>();

            if (group == null)
            {
                response.NotFound = true;
            }
            else
            {
                var count = await _privilegeRepository.Count();

                if (group.GroupPrivileges.Count() == count)
                {
                    var groups = await _repository.GetAll(c => c.GroupPrivileges);

                    if (groups.Any(c => c.GroupPrivileges.Count() != count))
                    {
                        response.CantDelete = true;
                    }
                    else
                    {
                        await _repository.Delete(group);

                        response.Data = _mapper.Map <GroupDto>(group);
                    }
                }
                else
                {
                    await _repository.Delete(group);

                    response.Data = _mapper.Map <GroupDto>(group);
                }
            }
            return(response);
        }
Beispiel #20
0
        public override async Task <ErrorRepsonse <UserDto> > AddAsync(CreateUserDto createDto)
        {
            var response = new ErrorRepsonse <UserDto>();

            if (await _repository.Any(c => c.UserName.ToLower() == createDto.UserName.ToLower()))
            {
                response.Errors.Add("UserName.Exisit");
                return(response);
            }
            if (await _repository.Any(c => c.Name == createDto.Name))
            {
                response.Errors.Add("Name.Exisit");
                return(response);
            }
            var user = _mapper.Map <User>(createDto);
            await _repository.AddAsync(user);

            response = new ErrorRepsonse <UserDto>(_mapper.Map <UserDto>(user));
            if (user.CanWorkAsAgent)
            {
                RemoveCash();
            }
            return(response);
        }