Example #1
0
        public ProfessionServices AddProfessionService(int userId, int professionId, string serviceName, string serviceUnit, float serviceUnitPrice, CurrencyEnum currency)
        {
            Users user = GetUserById(userId);

            if (user == null)
            {
                throw new NoEntryFoundException(userId, typeof(Users).Name);
            }

            UserProfessions profession = ProfessionRepository.GetByIdAndUserId(professionId, user.Id);

            if (profession == null)
            {
                throw new NoEntryFoundException(professionId, user.Id, typeof(UserProfessions).Name);
            }

            ProfessionServices service = new ProfessionServices
            {
                UserId           = user.Id,
                UserProfessionId = profession.Id,
                ServiceName      = serviceName,
                ServiceUnit      = serviceUnit,
                ServiceUnitPrice = serviceUnitPrice,
                ServiceUnitId    = (int)currency
            };

            ServiceRepository.Add(service);
            return(ServiceRepository.GetByIdAndUserId(service.Id, user.Id));
        }
Example #2
0
        public bool RemoveProfessionService(int userId, int serviceId)
        {
            Users user = GetUserById(userId);

            if (user == null)
            {
                throw new NoEntryFoundException(userId, typeof(Users).Name);
            }

            ProfessionServices service = ServiceRepository.GetByIdAndUserId(serviceId, user.Id);

            if (service == null)
            {
                throw new NoEntryFoundException(serviceId, user.Id, typeof(ProfessionServices).Name);
            }

            ServiceRepository.Remove(service);
            return(true);
        }
Example #3
0
        public ProfessionServices UpdateProfessionService(int userId, int serviceId, string serviceName, string serviceUnit, float serviceUnitPrice, CurrencyEnum currency)
        {
            Users user = GetUserById(userId);

            if (user == null)
            {
                throw new NoEntryFoundException(userId, typeof(Users).Name);
            }

            ProfessionServices existingService = ServiceRepository.GetByIdAndUserId(serviceId, user.Id);

            if (existingService == null)
            {
                throw new NoEntryFoundException(serviceId, userId, typeof(ProfessionServices).Name);
            }

            existingService.ServiceName      = serviceName;
            existingService.ServiceUnit      = serviceUnit;
            existingService.ServiceUnitPrice = serviceUnitPrice;
            existingService.ServiceUnitId    = (int)currency;

            ServiceRepository.Update(existingService);
            return(ServiceRepository.GetByIdAndUserId(existingService.Id, user.Id));;
        }