public void DeleteCustomer(CustomerViewModel customer, int userId)
 {
     Customer selectedCustomer = _customerRepository.GetById<int>(customer.Id);
     selectedCustomer.Status = (int)DbConstant.DefaultDataStatus.Deleted;
     selectedCustomer.ModifyUserId = userId;
     selectedCustomer.ModifyDate = DateTime.Now;
     _unitOfWork.SaveChanges();
 }
 public void UpdateCustomer(CustomerViewModel customer, int userId)
 {
     Customer entity = _customerRepository.GetById<int>(customer.Id);
     Map(customer, entity);
     _customerRepository.AttachNavigation<City>(entity.City);
     entity.ModifyDate = DateTime.Now;
     entity.ModifyUserId = userId;
     _customerRepository.Update(entity);
     _unitOfWork.SaveChanges();
 }
        public void InsertCustomer(CustomerViewModel customer, int userId)
        {
            using(var trans = _unitOfWork.BeginTransaction())
            {
                try
                {
                    Customer entity = new Customer();
                    Map(customer, entity);
                    _customerRepository.AttachNavigation<City>(entity.City);
                    entity.CreateUserId = entity.ModifyUserId = userId;
                    entity.CreateDate = entity.ModifyDate = DateTime.Now;
                    entity.Status = (int)DbConstant.DefaultDataStatus.Active;
                    _customerRepository.Add(entity);
                    _unitOfWork.SaveChanges();

                    trans.Commit();
                }
                catch (System.Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
            }
        }
 public override void RefreshDataView()
 {
     if (!bgwMain.IsBusy)
     {
         MethodBase.GetCurrentMethod().Info("Fecthing customer data...");
         _selectedCustomer = null;
         FormHelpers.CurrentMainForm.UpdateStatusInformation("Memuat data customer...", false);
         bgwMain.RunWorkerAsync();
     }
 }