Пример #1
0
        public BasicResponse Save(ClientDTO dto)
        {
            var response = new BasicResponse();
            try
            {
                var entity = new Client
                {
                    Code = dto.Code,
                    Id = dto.Id,
                    Name = dto.Name,
                    IsActive = true,
                };
                _clientRepository.Save(entity);
                response.Status = true;
                response.Info = "Success";

            }

            catch (Exception ex)
            {
                response.Status = false;
                if (ex is DomainValidationException)
                {
                    var dex = ex as DomainValidationException;
                    response.Info = dex.FormatException();
                }
                else
                {
                    response.Status = false;
                    response.Info = ex.Message;
                }

            }
            return response;
        }
Пример #2
0
        public void Save(Client entity)
        {
            ValidationResultInfo vri = Validate(entity);
            if (!vri.IsValid)
                throw new DomainValidationException(vri, "Client  Details not Valid");
            DateTime date = DateTime.Now;
            Client tbl = _context.Clients.FirstOrDefault(s => s.Id == entity.Id);
            if (tbl == null)
            {
                tbl = new Client();
                tbl.CreatedOn = date;
                tbl.IsActive = true;
                tbl.Id = entity.Id;
                _context.Clients.Add(tbl);
            }
            tbl.Name = entity.Name;

            tbl.Code = entity.Code;

            tbl.UpdatedOn = date;

            _context.SaveChanges();
        }
Пример #3
0
 public ValidationResultInfo Validate(Client itemToValidate)
 {
     return itemToValidate.BasicValidation();
 }
Пример #4
0
        private Client GetClient()
        {
            var client = _context.Clients.FirstOrDefault(s => s.Code == "SAF");
            var date = DateTime.Now;
            if(client==null)
            {
                client= new Client();
                client.Id = Guid.NewGuid();
                _context.Clients.Add(client);
                client.Code = "SAF";
                client.Name = "SAFARICOM";
                client.IsActive = true;
                client.CreatedOn = date;
                client.UpdatedOn = date;
                var user1 = new User
                                {
                                    ClientId = client.Id,
                                    CreatedOn = date,
                                    Email = "",
                                    Fullname = "safadmin",
                                    Id = Guid.NewGuid(),
                                    IsActive = false,
                                    Password = Md5Hash.GetMd5Hash("1234"),
                                    PhoneNumber = "00000000",
                                    UserType = UserType.Admin,
                                    UpdatedOn = date,
                                    Username = "******"

                                };
                _context.Users.Add(user1);
                var user2 = new User
                {
                    ClientId = client.Id,
                    CreatedOn = date,
                    Email = "",
                    Fullname = "saftdr",
                    Id = Guid.NewGuid(),
                    IsActive = false,
                    Password = Md5Hash.GetMd5Hash("1234"),
                    PhoneNumber = "00000000",
                    UserType = UserType.TDR,
                    UpdatedOn = date,
                    Username = "******"

                };
                _context.Users.Add(user2);

                _context.SaveChanges();
            }

            return client;
        }
Пример #5
0
 private ClientDTO Map(Client entity)
 {
     if (entity == null)
         return null;
     var dto = new ClientDTO
     {
         Code = entity.Code,
         Id = entity.Id,
         IsActive = entity.IsActive,
         Name = entity.Name,
     };
     return dto;
 }