Exemplo n.º 1
0
        public static ManifacturerViewModel MapToViewModel(this Manifacturer manifacturer)
        {
            var viewModel = new ManifacturerViewModel();

            viewModel.Id      = manifacturer.Id;
            viewModel.Name    = manifacturer.Name;
            viewModel.City    = manifacturer.City;
            viewModel.Country = manifacturer.Country;
            viewModel.Address = manifacturer.Address;

            return(viewModel);
        }
 public bool EditManufacturer(Manifacturer manufacturer)
 {
     using (var conn = new SqlConnection(_connectionString))
     {
         var sql = @"UPDATE Manifacturer SET [Name] = @Name, Description = @Description, CountryId = @CountryId WHERE ManifacturerId = @ManifacturerId";
         try
         {
             var affected = conn.Execute(sql, new { @Name = manufacturer.Name, @Description = manufacturer.Description, @CountryId = manufacturer.CountryId, @ManifacturerId = manufacturer.ManifacturerId });
         }
         catch (Exception)
         {
             return(false);
         }
     }
     return(true);
 }
 public bool AddManufacturer(Manifacturer manufacturer)
 {
     using (var conn = new SqlConnection(_connectionString))
     {
         var sql = @"INSERT INTO Manifacturer ([Name], Description, CountryId) VALUES (@Name, @Description, @CountryId)";
         try
         {
             var affected = conn.Execute(sql, new { @Name = manufacturer.Name, @Description = manufacturer.Description, @CountryId = manufacturer.CountryId });
         }
         catch (Exception)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 4
0
        public Guid Create(CreateManifacturerViewModel model)
        {
            _unitOfWork.BeginTransaction();

            var manifacturer = new Manifacturer(model.Name, model.City, model.Country, model.Address);
            var isUnique     = _manifacturerRepository.CheckUniqueness(manifacturer);

            if (!isUnique)
            {
                _unitOfWork.Commit();
                throw new Exception(ExceptionMessages.ManifacturerException.ALREADY_EXISTS);
            }
            _manifacturerRepository.Add(manifacturer);
            _unitOfWork.Commit();
            return(manifacturer.Id);
        }