Exemple #1
0
        public IActionResult PostClient([FromBody] ClientTypeCreateModel model)
        {
            Console.Write(model);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ClientTypeDto clientTypeDto = new ClientTypeDto()
            {
                ClientTypeName = model.ClientTypeName,
                CustomerId     = model.CustomerId,
                DateCreated    = DateTime.Now,
                DateModified   = DateTime.Now
            };

            try
            {
                var clientType = adminRepository.CreateClientType(clientTypeDto);
                if (clientType != null)
                {
                    return(Ok(clientType));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            return(NoContent());
        }
Exemple #2
0
 public IActionResult PostClient([FromBody] ClientTypeDto model)
 {
     Console.Write(model);
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         var clientType = adminRepository.CreateClientType(model);
         if (clientType != null)
         {
             return(Ok(clientType));
         }
         else
         {
             return(NoContent());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
     return(NoContent());
 }
        public void AddClientTypeOk()
        {
            NSI.REST.Models.ClientTypeCreateModel clientType = new ClientTypeCreateModel()
            {
                ClientTypeName = "firstClient",
                IsDeleted      = false,
                CustomerId     = 1,
                DateCreated    = DateTime.Now,
                DateModified   = DateTime.Now
            };

            var clientType1 = new ClientTypeDto()
            {
                ClientTypeId   = 1,
                ClientTypeName = "firstClient",
                IsDeleted      = false,
                CustomerId     = 1,
                DateCreated    = DateTime.Now,
                DateModified   = DateTime.Now
            };

            var mockRepo   = new Mock <IAdminManipulation>();
            var controller = new AdminController(mockRepo.Object);

            mockRepo.Setup(x => x.CreateClientType(It.IsAny <ClientTypeDto>())).Returns(clientType1);
            var result = controller.PostClient(clientType);

            Assert.IsType <OkObjectResult>(result);
        }
Exemple #4
0
        public void AddClientTypeTest()
        {
            var mockRepo   = new Mock <IAdminManipulation>();
            var controller = new AdminController(mockRepo.Object);

            // Empty Model state
            controller.ModelState.AddModelError("error", "some error");

            var result = controller.PostClient(new ClientTypeDto());

            Assert.IsType <BadRequestObjectResult>(result);

            //Bad Case Model

            var clientType = new ClientTypeDto()
            {
                ClientTypeId   = 1,
                ClientTypeName = "firstClient",
                IsDeleted      = false,
            };

            result = controller.PostClient(clientType);
            Assert.IsType <BadRequestObjectResult>(result);

            //Bad Validation

            clientType.ClientTypeName = "......!!!";
            clientType.CustomerId     = 1;
            result = controller.PostClient(clientType);
            Assert.IsType <BadRequestObjectResult>(result);
        }
Exemple #5
0
        public void GetAllClientsTest()
        {
            var clientType = new ClientTypeDto()
            {
                ClientTypeId   = 1,
                ClientTypeName = "firstClient",
                IsDeleted      = false,
                CustomerId     = 1,
                DateCreated    = DateTime.Now,
                DateModified   = DateTime.Now
            };

            var clientType2 = new ClientTypeDto()
            {
                ClientTypeId   = 2,
                ClientTypeName = "secondClient",
                IsDeleted      = false,
                CustomerId     = 1,
                DateCreated    = DateTime.Now,
                DateModified   = DateTime.Now
            };

            var mockRepo = new Mock <IAdminManipulation>();

            mockRepo.Setup(x => x.CreateClientType(It.IsAny <ClientTypeDto>())).Returns(clientType);
            var controller = new AdminController(mockRepo.Object);

            controller.PostClient(clientType);
            controller.PostClient(clientType2);

            var clientTypes = controller.GetClients();

            Assert.IsType <OkObjectResult>(clientTypes);
        }
Exemple #6
0
        public IActionResult PutClient(int id, [FromBody] ClientTypeEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ClientTypeDto clientTypeDto = new ClientTypeDto()
            {
                ClientTypeId   = model.ClientTypeId,
                ClientTypeName = model.ClientTypeName,
                CustomerId     = model.CustomerId,
                DateCreated    = DateTime.Now,
                DateModified   = DateTime.Now
            };

            try
            {
                var clientType = adminRepository.EditClientType(id, clientTypeDto);
                if (clientType)
                {
                    return(Ok(clientType));
                }
                else
                {
                    return(NoContent());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #7
0
        public void UpdateClientTypeTest()
        {
            var clientType = new ClientTypeDto()
            {
                ClientTypeId   = 10,
                ClientTypeName = "firstClient",
                IsDeleted      = false,
                CustomerId     = 1,
                DateCreated    = DateTime.Now,
                DateModified   = DateTime.Now
            };

            var mockRepo = new Mock <IAdminManipulation>();

            mockRepo.Setup(x => x.CreateClientType(It.IsAny <ClientTypeDto>())).Returns(clientType);
            var controller = new AdminController(mockRepo.Object);

            controller.PostClient(clientType);

            //No content Result

            clientType.ClientTypeName = "NewName";
            var result = controller.PutClient(1, clientType);

            Assert.IsType <NoContentResult>(result);

            //Bad Case Model
            controller.ModelState.AddModelError("error", "some error");

            result = controller.PutClient(30, model: null);
            Assert.IsType <BadRequestObjectResult>(result);
        }
Exemple #8
0
        public void DeleteClientTypeTest()
        {
            var clientType = new ClientTypeDto()
            {
                ClientTypeId   = 10,
                ClientTypeName = "firstClient",
                IsDeleted      = false,
                CustomerId     = 1,
                DateCreated    = DateTime.Now,
                DateModified   = DateTime.Now
            };

            var mockRepo   = new Mock <IAdminManipulation>();
            var controller = new AdminController(mockRepo.Object);

            controller.ModelState.AddModelError("error", "some error");

            // Invalid Model
            var result = controller.DeleteClient(10000);

            Assert.IsType <NoContentResult>(result);

            //OK
            mockRepo.Setup(x => x.CreateClientType(It.IsAny <ClientTypeDto>())).Returns(clientType);
            mockRepo.Setup(x => x.DeleteClientTypeById(It.IsAny <int>())).Returns(true);
            controller.PostClient(clientType);

            result = controller.DeleteClient(10);
            Assert.IsType <OkObjectResult>(result);
        }
 public static ClientTypeModel ToModel(this ClientTypeDto clientType)
 {
     return(new ClientTypeModel()
     {
         ClientTypeId = clientType.ClientTypeId,
         MinutePrice = clientType.MinutePrice,
         SMSPrice = clientType.SMSPrice,
         TypeName = clientType.TypeName
                    //Clients = clientType.Clients.Select(c => c.ToModel()).ToList()
     });
 }
        //Client Type

        public static ClientType MapToDbEntityClient(ClientTypeDto clientTypeDto)
        {
            return(new ClientType()
            {
                ClientTypeId = clientTypeDto.ClientTypeId,
                ClientTypeName = clientTypeDto.ClientTypeName,
                DateCreated = clientTypeDto.DateCreated,
                DateModified = clientTypeDto.DateModified,
                IsDeleted = clientTypeDto.IsDeleted,
                CustomerId = clientTypeDto.CustomerId
            });
        }
Exemple #11
0
        public async Task <(bool created, ClientTypes clientType)> CreateClientType(ClientTypeDto clientTypeDto)
        {
            var clientType = Mapper.Map <ClientTypes>(clientTypeDto);

            if (clientTypeDto.ClientTypeId == Guid.Empty)
            {
                clientType.SetNewId();
            }
            var result = await _clientTypeRepository.Add(clientType);

            return(result, clientType);
        }
Exemple #12
0
        public double GetSmsPrice(ClientDto item, ClientTypeDto clientType)
        {
            double        smsPrice   = clientType.SMSPrice;
            List <SMSDto> smss       = _smsManager.GetSMSDtos(item.ClientId).Where(s => s.Time.Month == DateTime.Now.Month).ToList();
            double        totalPrice = 0;

            foreach (var sms in smss)
            {
                if (sms != null)
                {
                    totalPrice += sms.ExternalPrice + smsPrice;
                }
            }
            return(totalPrice);
        }
Exemple #13
0
 public static ClientTypeEntity ToModel(this ClientTypeDto clientType)
 {
     if (clientType == null)
     {
         return(null);
     }
     return(new ClientTypeEntity()
     {
         ClientTypeId = clientType.ClientTypeId,
         MinutePrice = clientType.MinutePrice,
         SMSPrice = clientType.SMSPrice,
         TypeName = clientType.TypeName,
         //Clients = clientType.Clients.Select(c => c.ToModel()).ToList()
     });
 }
Exemple #14
0
 public ClientTypeDto CreateClientType(ClientTypeDto model)
 {
     try
     {
         var clientType = Mappers.AdminRepository.MapToDbEntityClient(model);
         clientType.DateModified = clientType.DateCreated = DateTime.Now;
         clientType.IsDeleted    = false;
         _dbContext.Add(clientType);
         if (_dbContext.SaveChanges() != 0)
         {
             return(Mappers.AdminRepository.MapToDtoClient(clientType));
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.InnerException);
         throw new Exception("Cannot create new client type!");
     }
     return(null);
 }
 public ClientTypeDto CreateClientType(ClientTypeDto clientTypeDto)
 {
     try
     {
         var clientType = Mappers.AdminRepository.MapToDbEntityClient(clientTypeDto);
         clientType.DateModified = clientType.DateCreated = DateTime.Now;
         clientType.IsDeleted    = false;
         _dbContext.Add(clientType);
         if (_dbContext.SaveChanges() != 0)
         {
             return(Mappers.AdminRepository.MapToDtoClient(clientType));
         }
     }
     catch (Exception ex)
     {
         //log ex
         throw new Exception(ex.Message);
     }
     return(null);
 }
Exemple #16
0
 public bool EditClientType(int clientTypeId, ClientTypeDto model)
 {
     try
     {
         var clientType = _dbContext.ClientType.FirstOrDefault(x => x.ClientTypeId == clientTypeId);
         if (clientType != null)
         {
             clientType.ClientTypeName = model.ClientTypeName;
             clientType.CustomerId     = model.CustomerId;
             clientType.DateModified   = DateTime.Now;
             _dbContext.SaveChanges();
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.InnerException);
         throw new Exception("Cannot update client type!");
     }
 }
 public bool EditClientType(int clientTypeId, ClientTypeDto clientTypeDto)
 {
     try
     {
         var clientType = _dbContext.ClientType.FirstOrDefault(x => x.ClientTypeId == clientTypeId);
         if (clientType != null)
         {
             clientType.ClientTypeName = clientTypeDto.ClientTypeName;
             clientType.CustomerId     = clientTypeDto.CustomerId;
             clientType.DateModified   = DateTime.Now;
             _dbContext.SaveChanges();
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         //log ex
         throw new Exception(ex.Message);
     }
 }
Exemple #18
0
        public IEnumerable <string> MostValuableClients()
        {
            Dictionary <ClientDto, double> dictionary = new Dictionary <ClientDto, double>();

            foreach (var item in _clientManager.GetClientDtos())
            {
                ClientTypeDto clientType = _clientTypeManager.GetClientTypeDto(item.ClientTypeId);
                double        value      = GetCallsPrice(item, clientType) + GetPackageIncludesPrice(item) + GetPackagePrice(item) + GetSmsPrice(item, clientType);
                dictionary.Add(item, value);
            }
            var sortedDictionary = from v in dictionary
                                   orderby v.Value descending
                                   select v;
            List <string> list = new List <string>();

            foreach (var item in sortedDictionary)
            {
                list.Add($"{item.Key.FirstName} {item.Key.LastName} has a value of {item.Value}");
            }
            return(list.Take(3));
        }
Exemple #19
0
 public double GetCallsPrice(ClientDto item, ClientTypeDto clientType)
 {
     try
     {
         double          callPrice  = clientType.MinutePrice;
         List <CallsDto> calls      = _callManager.GetCallsOfClient(item.ClientId).Where(c => c.Time.Month == DateTime.Now.Month).ToList();
         double          totalPrice = 0;
         foreach (var call in calls)
         {
             if (call != null)
             {
                 totalPrice += call.ExternalPrice + callPrice;
             }
         }
         return(totalPrice);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         return(0);
     }
 }
Exemple #20
0
 public IActionResult PutClient(int id, [FromBody] ClientTypeDto model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         var clientType = adminRepository.EditClientType(id, model);
         if (clientType)
         {
             return(Ok(clientType));
         }
         else
         {
             return(NoContent());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
 public ClientTypeDto CreateClientType(ClientTypeDto clientTypeDto)
 {
     return(_adminRepository.CreateClientType(clientTypeDto));
 }
        public async Task <ActionResult> Edit(ClientTypeDto ClientType)
        {
            await _ClientTypeAppService.Update(ClientType);

            return(RedirectToAction("Index"));
        }
Exemple #23
0
 public ClientTypeDto CreateClientType(ClientTypeDto model)
 {
     return(_adminRepository.CreateClientType(model));
 }
Exemple #24
0
 public bool EditClientType(int clientTypeId, ClientTypeDto clientTypeDto)
 {
     return(_adminRepository.EditClientType(clientTypeId, clientTypeDto));
 }
Exemple #25
0
        public async Task <(bool updated, ClientTypes clientType)> UpdateClientType(Guid clientTypeId, ClientTypeDto clientTypeDto)
        {
            var existingClientType = await _clientTypeRepository.GetById(clientTypeId);

            if (existingClientType == null)
            {
                return(false, null);
            }

            Mapper.Map(clientTypeDto, existingClientType);

            var result = await _clientTypeRepository.Update(existingClientType);

            return(result, existingClientType);
        }
 public bool EditClientType(int clientTypeId, ClientTypeDto clientType)
 {
     throw new NotImplementedException();
 }
Exemple #27
0
        public async Task <ClientTypeModel> GetClientType(int typeId)
        {
            ClientTypeDto dto = await invoice.GetClientTypeAsync(typeId);

            return(dto.ToModel1());
        }