Beispiel #1
0
        public void UpdateCustomerInDatabase(DTOCustomer customer)
        {
            try
            {
                string query = $"update Customers set Name = @name where id = @id";

                using (SqlCommand command = new SqlCommand(query, conn))
                {
                    command.Parameters.AddWithValue("@id", customer.CustomerId);
                    command.Parameters.AddWithValue("@name", customer.Name);

                    conn.Open();
                    int result = command.ExecuteNonQuery();
                    conn.Close();

                    // Check Error
                    if (result < 0)
                    {
                        Console.WriteLine("Error inserting data into Database!");
                    }
                    else
                    {
                        Console.WriteLine("nu er der vistnok opdateret en kunde i databasen");
                    }
                }
            }
            catch
            {
                Console.WriteLine("Kunde ikke rettet i SQL-Databasen");
            }
        }
        public DTOCustomer AddCustomerToBLL(DTOCustomer c)
        {
            DalCustomer dc = new DalCustomer();

            return(Converters.Converters.ConvertCustomerToDTO
                       (dc.addCusstomerToSQL(Converters.Converters.ConvertCustomerToDAL(c))));
        }
Beispiel #3
0
        public List <DTOCustomer> GetCustomers()
        {
            var customers = new List <DTOCustomer>();

            using (_dbCon.Open())
            {
                string query = "SELECT * FROM [dbi431200].[dbo].[Customer]";
                //using, closes the connection at the end for you.
                // ||
                // \/
                using (SqlCommand command = new SqlCommand(query, _dbCon.connection))
                {
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        DTOCustomer customerDTO = new DTOCustomer
                        {
                            CustomerID = reader.GetString(0),
                            Name       = reader.GetString(1),
                            Adress     = reader.GetString(2),
                            Email      = reader.GetString(3)
                        };

                        customers.Add(customerDTO);
                    }
                }
            }
            return(customers);
        }
Beispiel #4
0
        public void InsertCustomerIntoDatabase(DTOCustomer customer)
        {
            try
            {
                string query = $"insert into customers(Id, Name) values(@id,@name)";

                using (SqlCommand command = new SqlCommand(query, conn))
                {
                    command.Parameters.AddWithValue("@id", customer.CustomerId);
                    command.Parameters.AddWithValue("@name", customer.Name);

                    conn.Open();
                    int result = command.ExecuteNonQuery();
                    conn.Close();
                    // Check Error
                    if (result < 0)
                    {
                        Console.WriteLine("Error inserting data into Database!");
                    }
                    else
                    {
                        Console.WriteLine("nu er der vistnok skrevet en kunde i databasen");
                    }
                }
            }
            catch
            {
                Console.WriteLine("kunde ikke skrevet i SQL-databasen");
            }
        }
Beispiel #5
0
        public IActionResult AddCustomer()
        {
            DTOCustomer model = new DTOCustomer();

            model.Cities = _unitOfWork.Customers.GetCities().Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList();
            return(View("AddEditCustomer", model));
        }
        public Task <DataResult <DTOCustomer> > CreateAsync(DTOCustomer customerDTO, bool isCreateGenerateId = false)
        {
            return(Task.Run(() => {
                var createdCustomerDTO = new DTOCustomer();

                //if (customerRepository.ExistByCondition(x => x.Name == customerDTO.Name))
                //    return new DataResult<DTOCustomer> { Errors = new List<ErrorDescriber> { new ErrorDescriber("Existed Customer Name") }, Target = customerDTO };

                //if (customerRepository.ExistByCondition(x => x.Phone == customerDTO.Phone))
                //    return new DataResult<DTOCustomer> { Errors = new List<ErrorDescriber> { new ErrorDescriber("Existed Customer Phone") }, Target = customerDTO };

                //if (customerRepository.ExistByCondition(x => !string.IsNullOrEmpty(x.Email) && x.Email == customerDTO.Email))
                //    return new DataResult<DTOCustomer> { Errors = new List<ErrorDescriber> { new ErrorDescriber("Existed Customer Email") }, Target = customerDTO };

                var customerEntity = _mapper.Map <Customer>(customerDTO);

                string garageShortName = garageInfoRepository.GetFirstOrDefault()?.ShortName;
                var identityNumber = customerRepository.Identity(x => x.GenerateId) != null ? customerRepository.Identity(x => x.GenerateId).GenerateId : 0;

                customerEntity.Id = garageShortName + IdentityGenerate.Create(identityNumber, new string[] { "", EntityPrefix.Customer.ToDefaultValue() }, NumberUnitType.Large);
                customerEntity.CreatedDate = DateTime.Now;

                var createdCustomerEntity = customerRepository.Insert(customerEntity);
                _unitOfWork.SaveChanges();

                createdCustomerDTO = _mapper.Map <DTOCustomer>(createdCustomerEntity);

                return new DataResult <DTOCustomer> {
                    Errors = new List <ErrorDescriber>(), Target = createdCustomerDTO
                };
            }));
        }
        public async Task <IHttpActionResult> Post([FromBody] DTOCustomer customerDTO)
        {
            Result errorResult           = null;
            var    customerCreatedResult = await _customerService.CreateAsync(customerDTO);

            if (!customerCreatedResult.HasErrors)
            {
                var attachCustomerToCustomerExchangeResult = await _customerExchangeService.AttachNewCustomerToCustomerExchangeAsync(customerCreatedResult.Target.Id);

                if (!attachCustomerToCustomerExchangeResult.HasErrors)
                {
                    customerCreatedResult.Target.CustomerExchangeId = attachCustomerToCustomerExchangeResult.Target.Id;
                    var successResult = SuccessResult(customerCreatedResult.Target);
                    return(Ok(successResult));
                }
                else
                {
                    errorResult = ErrorResult(attachCustomerToCustomerExchangeResult.Errors);
                }
            }
            else
            {
                errorResult = ErrorResult(customerCreatedResult.Errors);
            }

            return(Content(HttpStatusCode.InternalServerError, errorResult));
        }
Beispiel #8
0
        public DTOCustomer ToDTO(Customer customer)
        {
            DTOCustomer customerDTO = new DTOCustomer();

            customerDTO.Name          = customer.Name;
            customerDTO.Authorized    = customer.Authorized;
            customerDTO.CariHesapKodu = customer.CariHesapKodu;
            customerDTO.CariType      = customer.CariType;
            customerDTO.Address       = customer.Address;
            customerDTO.Comment       = customer.Comment;
            customerDTO.Email         = customer.Email;
            customerDTO.Fax           = customer.Fax;
            customerDTO.Phone         = customer.Phone;
            customerDTO.Phone2        = customer.Phone2;
            customerDTO.RiskStatus    = customer.RiskStatus;
            customerDTO.TaxNumber     = customer.TaxNumber;
            customerDTO.TaxRoom       = customer.TaxRoom;
            customerDTO.WebSite       = customer.WebSite;
            string Tarih = customer.KayıtTarihi.ToString();

            customerDTO.Date        = Tarih.Substring(0, 10);
            customerDTO.TimeRegiser = customer.KayıtTarihi.ToString("HH:mm");



            customerDTO.ID = customer.ID;

            return(customerDTO);
        }
Beispiel #9
0
        private void SetUpQueue(object queueType)
        {
            Console.WriteLine("nu startes :" + (string)queueType);

            string jsonstring = "";

            var connection = factory.CreateConnection();
            var channel    = connection.CreateModel();


            channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);

            Console.WriteLine(" [*] Waiting for messages.");

            var consumer = new EventingBasicConsumer(channel);

            consumer.Received += (sender, ea) =>
            {
                var body    = ea.Body.ToArray();
                var message = Encoding.UTF8.GetString(body);
                Console.WriteLine("besked modtaget [x] Received {0}", message);
                jsonstring = message;

                switch (queueType)
                {
                case "customercreate_queue":
                    DTOCustomer insertCustomer = Mapper.ConvertFromJsonToDTOCustomer(jsonstring);
                    database.InsertCustomerIntoDatabase(insertCustomer);
                    break;

                case "customerupdate_queue":
                    DTOCustomer upateCustomer = Mapper.ConvertFromJsonToDTOCustomer(jsonstring);
                    database.UpdateCustomerInDatabase(upateCustomer);
                    break;

                case "ressourceCreate_queue":
                    DTORessource createRessource = Mapper.ConvertFromJsonToDTOResource(jsonstring);
                    database.InsertRessourceInDataBase(createRessource);
                    break;

                case "ressourceUpdate_queue":
                    DTORessource updateRessource = Mapper.ConvertFromJsonToDTOResource(jsonstring);
                    database.UpdataRessourceInDataBase(updateRessource);
                    break;

                default:
                    // code block
                    break;
                }
                Console.WriteLine(" [x] Done");

                // Note: it is possible to access the channel via
                //       ((EventingBasicConsumer)sender).Model here
                channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
            };
            channel.BasicConsume(queue: (string)queueType,
                                 autoAck: false,
                                 consumer: consumer);
        }
 public void AddCustomer(DTOCustomer MyNewCustomer)
 {
     if (GetCustomersById(MyNewCustomer.customerID) == null)
     {
         myBllCustomers.AddCustomerToBLL(MyNewCustomer);
     }
     //אם קיים במערכת -אין צורך להוסיפו!
 }
Beispiel #11
0
        public static Customer ConvertCustomerToDAL(DTOCustomer cus)
        {
            Customer customer = new Customer()
            {
                customerPhoneNo = cus.customerPhoneNo,
                customerID      = cus.customerID
            };

            return(customer);
        }
Beispiel #12
0
 public frmSearchCustomer()
 {
     InitializeComponent();
     customerDataTable        = new DataTable();
     customerBUS              = new BUSCustomer();
     customerObject           = new DTOCustomer();
     customerMultiSelect      = new GridCheckMarksSelection(grdvListCustomer);
     ruleBUS                  = new BUSRule();
     CustomerSno.VisibleIndex = 1;
 }
Beispiel #13
0
 /// <summary>
 /// Phương thức thêm mới một Customer vào csdl
 /// </summary>
 /// <returns>true: thêm mới thành công, false: thêm mới thất bại</returns>
 public bool InsertCustomer(DTOCustomer Customer)
 {
     try
     {
         return(customerDAO.InsertCustomer(Customer));
     }
     catch (SqlException)
     {
         throw;
     }
 }
Beispiel #14
0
        public static DTOCustomer ConvertCustomerToDTO(Customer cus)
        {
            DTOCustomer customer = new DTOCustomer()
            {
                customerID      = cus.customerID,
                customerPhoneNo = cus.customerPhoneNo
            };


            return(customer);
        }
Beispiel #15
0
 /// <summary>
 /// Phương thức cập nhật một Customer xuống csdl theo id
 /// </summary>
 /// <returns>true: thêm mới thành công, false: thêm mới thất bại</returns>
 public bool UpdateCustomer(DTOCustomer Customer)
 {
     try
     {
         return(customerDAO.UpdateCustomer(Customer));
     }
     catch (SqlException)
     {
         throw;
     }
 }
        public IActionResult EditCustomer(int id)
        {
            DTOCustomer model = _customerService.GetByIdDto(id);

            if (model == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            model.Cities = _customerService.GetCities().Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList();
            return(View("AddEditCustomer", model));
        }
Beispiel #17
0
        public IActionResult EditCustomer(int id)
        {
            Customer    customer = _unitOfWork.Customers.GetById(id);
            DTOCustomer model    = new DTOCustomer();

            if (customer == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            model        = _mapper.Map <DTOCustomer>(customer);
            model.Cities = _unitOfWork.Customers.GetCities().Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList();
            return(View("AddEditCustomer", model));
        }
Beispiel #18
0
        public void Edit(DTOCustomer model)
        {
            Address      address  = _mapper.Map <Address>(model.Address);
            PhoneNumber  phone    = model.PhoneNumber;
            EmailAddress email    = model.EmailAddress;
            Customer     customer = _mapper.Map <Customer>(model);

            _context.Update(address);
            _context.Update(phone);
            _context.Update(email);
            _context.SaveChanges();

            base.Edit(customer);
        }
Beispiel #19
0
 /// <summary>
 /// Phương thức cập nhật một Customer xuống csdl theo id
 /// </summary>
 /// <returns>true: thêm mới thành công, false: thêm mới thất bại</returns>
 public bool UpdateCustomer(DTOCustomer Customer)
 {
     try
     {
         DataExecute.Instance.createSqlCmd("sp_EditCustomerUpdate" /*Truyen vao storeprocedure*/, new object[8] {
             Customer.CustomerID, Customer.Name, Customer.Gender, Customer.Birthday, Customer.Address, Customer.Phone, Customer.Email, Customer.NumberID
         });
         return(DataExecute.Instance.updateData(DataConnection.Instance.m_cmd) > 0);
     }
     catch (SqlException)
     {
         throw;
     }
 }
        public async Task <IHttpActionResult> Put(string customerId, [FromBody] DTOCustomer customerDTO)
        {
            customerDTO.Id = customerId;
            var result = await CallAsyncWithRetry(() => _customerService.EditAsync(customerDTO));

            if (!result.HasErrors)
            {
                var successResult = SuccessResult(result.Target);
                return(Ok(successResult));
            }

            var errorResult = ErrorResult(result.Errors);

            return(Content(HttpStatusCode.InternalServerError, errorResult));
        }
Beispiel #21
0
        public void CreateCustomer(DTOCustomer C1)
        {
            using (_dbCon.Open())
            {
                string query = "INSERT INTO Customer (CustomerID, Name, Adress, Email) VALUES (@CustomerID, @Name, @Adress, @Email);";
                using (SqlCommand command = new SqlCommand(query, _dbCon.connection))
                {
                    command.Parameters.AddWithValue("@CustomerID", C1.CustomerID);
                    command.Parameters.AddWithValue("@Name", C1.Name);
                    command.Parameters.AddWithValue("@Adress", C1.Adress);
                    command.Parameters.AddWithValue("@Email", C1.Email);


                    command.ExecuteNonQuery();
                }
            }
        }
Beispiel #22
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!checkData())
            {
                return;
            }
            try
            {
                if (m_IsAdd)
                {
                    customerObject = new DTOCustomer("KH000000", txtCustomerName.Text, cmbCustomerGender.Text, dateBirthDay.DateTime,
                                                     txtCustomerAddress.Text, txtCustomerPhone.Text, txtCustomerEmail.Text, txtCMND.Text);

                    if (customerBUS.InsertCustomer(customerObject))
                    {
                        XtraCustomMessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", true, 1);
                    }
                    else
                    {
                        XtraCustomMessageBox.Show("Thêm dữ liệu thất bại!", "Lỗi", true, 4);
                    }
                }
                else
                {
                    customerObject = new DTOCustomer(txtCustomerId.Text, txtCustomerName.Text, cmbCustomerGender.Text, dateBirthDay.DateTime,
                                                     txtCustomerAddress.Text, txtCustomerPhone.Text, txtCustomerEmail.Text, txtCMND.Text);

                    if (customerBUS.UpdateCustomer(customerObject))
                    {
                        XtraCustomMessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", true, 1);
                    }
                    else
                    {
                        XtraCustomMessageBox.Show("Cập nhật dữ liệu thất bại!", "Lỗi", true, 4);
                    }
                }
            }
            catch (System.Exception)
            {
                XtraCustomMessageBox.Show("Lưu dữ liệu thất bại!", "Lỗi", true, 4);
            }
            finally
            {
                updateEnableButtonAndResetValueOfControl(ref btnSave);
            }
        }
Beispiel #23
0
        public void Add(DTOCustomer model)
        {
            Address      address  = _mapper.Map <Address>(model.Address);
            PhoneNumber  phone    = model.PhoneNumber;
            EmailAddress email    = model.EmailAddress;
            Customer     customer = _mapper.Map <Customer>(model);

            _context.Add(address);
            _context.Add(phone);
            _context.Add(email);
            _context.SaveChanges();

            customer.AddressId      = address.Id;
            customer.PhoneNumberId  = phone.Id;
            customer.EmailAddressId = email.Id;

            base.Add(customer);
        }
Beispiel #24
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (customerMultiSelect.Selection.Count == 0)
     {
         XtraCustomMessageBox.Show("Chưa có dòng dữ liệu nào được chọn!", "Cảnh báo", true, 3);
         return;
     }
     try
     {
         ArrayList _listCustomerId = new ArrayList();
         grdvListCustomer.FocusedRowHandle -= 1;
         foreach (DataRowView _rowData in customerMultiSelect.Selection)
         {
             customerObject            = new DTOCustomer();
             customerObject.CustomerID = _rowData["CustomerID"].ToString();
             if (!customerBUS.DeleteCustomer(customerObject.CustomerID))
             {
                 _listCustomerId.Add(_rowData["CustomerID"]);
             }
         }
         if (_listCustomerId.Count != 0)
         {
             String _erroContent = "Không thể xóa các khách hàng có mã: \n";
             foreach (var item in _listCustomerId)
             {
                 _erroContent += item.ToString() + "\n";
             }
             XtraCustomMessageBox.Show(_erroContent, "Lỗi", true, 4);
         }
         else
         {
             XtraCustomMessageBox.Show("Xóa dữ liệu thành công!", "Thông báo", true, 1);
         }
     }
     catch (System.Exception)
     {
         XtraCustomMessageBox.Show("Xóa dữ liệu thất bại", "Lỗi", true, 4);
     }
     finally
     {
         updateEnableButtonAndResetValueOfControl(ref btnDelete);
     }
 }
Beispiel #25
0
        public IActionResult SaveCustomer(DTOCustomer model)
        {
            if (model.Id == 0)
            {
                _unitOfWork.Customers.Add(model);

                var n = new Notification
                {
                    DateTime = DateTime.Now,
                    Text     = $"New customer - {model.Name}",
                    UserId   = int.Parse(_userManager.GetUserId(HttpContext.User))
                };
                _notification.Create(n);
            }
            else
            {
                _unitOfWork.Customers.Edit(model);
            }
            return(RedirectToAction(nameof(Index)));
        }
        public Task <DataResult <DTOCustomer> > GetCustomerByIdAsync(string customerId)
        {
            return(Task.Run(() => {
                var customerDTO = new DTOCustomer();

                var customer = customerRepository.GetById(customerId);
                if (customer != null)
                {
                    customerDTO = _mapper.Map <DTOCustomer>(customer);
                }
                else
                {
                    var identityNumber = customerRepository.Identity(x => x.GenerateId) != null ? customerRepository.Identity(x => x.GenerateId).GenerateId : 0;
                    customerDTO.Id = IdentityGenerate.Create(identityNumber, new string[] { "", EntityPrefix.Customer.ToDefaultValue() }, NumberUnitType.Large);
                }

                return new DataResult <DTOCustomer> {
                    Errors = new List <ErrorDescriber>(), Target = customerDTO
                };
            }));
        }
Beispiel #27
0
        public void Create(CustomerModel customer, ShoppingCartModel shoppingCartModel, List <CartItemModel> cartItemModel)
        {
            if (!customerVal.isCustomerNew(customer, GetAllCustomers()))
            {
                var CustomerID = customer.GeneratedID();
                var CartID     = customer.GeneratedID();

                var _dto = new DTOCustomer()
                {
                    CustomerID = CustomerID,
                    Name       = customer.Name,
                    Adress     = customer.Adress,
                    Email      = customer.Email
                };

                customer.CreateCart(shoppingCartModel, CustomerID, CartID);

                foreach (var item in cartItemModel)
                {
                    var model = new CartItemModel(CartID, item.DrinkID, item.Quantity);
                    cartColl.Create(model, CartID);
                }

                CustomerFactory.customerConnectionHandler.CreateCustomer(_dto);
            }
            else
            {
                var CartID           = customer.GeneratedID();
                var existingCustomer = customerVal.getExistingCustomer(customer.Email, GetAllCustomers());
                var CustomerID       = existingCustomer.First().CustomerID;
                customer.CreateCart(shoppingCartModel, CustomerID, CartID);

                foreach (var item in cartItemModel)
                {
                    var model = new CartItemModel(CartID, item.DrinkID, item.Quantity);
                    cartColl.Create(model, CartID);
                }
            }
        }
        public Task <DataResult <DTOCustomer> > EditAsync(DTOCustomer customerDTO)
        {
            return(Task.Run(() => {
                //if (customerRepository.ExistByCondition(x => x.Name == customerDTO.Name && x.Id != customerDTO.Id))
                //    return new DataResult<DTOCustomer> { Errors = new List<ErrorDescriber> { new ErrorDescriber("Existed Customer Name") }, Target = customerDTO };

                //if (customerRepository.ExistByCondition(x => x.Phone == customerDTO.Phone && x.Id != customerDTO.Id))
                //    return new DataResult<DTOCustomer> { Errors = new List<ErrorDescriber> { new ErrorDescriber("Existed Customer Phone") }, Target = customerDTO };

                //if (customerRepository.ExistByCondition(x => x.Email == customerDTO.Email && !string.IsNullOrEmpty(x.Email) && x.Id != customerDTO.Id))
                //    return new DataResult<DTOCustomer> { Errors = new List<ErrorDescriber> { new ErrorDescriber("Existed Customer Email") }, Target = customerDTO };

                var customerEntity = _mapper.Map <Customer>(customerDTO);
                var updatedCustomerDTO = new DTOCustomer();
                if ((customerRepository.ExistByCondition(x => (x.Name == customerEntity.Name && x.Id == customerEntity.Id))) || (!customerRepository.ExistByCondition(x => x.Name == customerEntity.Name)))
                {
                    customerEntity.ModifiedDate = DateTime.Now;

                    var updatedCustomerEntity = customerRepository.Update(customerEntity);
                    _unitOfWork.SaveChanges();

                    updatedCustomerDTO = _mapper.Map <DTOCustomer>(updatedCustomerEntity);

                    return new DataResult <DTOCustomer> {
                        Errors = new List <ErrorDescriber>(), Target = updatedCustomerDTO
                    };
                }
                else
                {
                    return new DataResult <DTOCustomer> {
                        Errors = new List <ErrorDescriber> {
                            new ErrorDescriber("Existed Customer Name")
                        }, Target = updatedCustomerDTO
                    };
                }
            }));
        }