Beispiel #1
0
        public bool Delete(Customer customer, CustomerFiles customerFiles)
        {
            db.Customers.Remove(customer);
            int isChanged = db.SaveChanges();

            db.CustomerFiles.Remove(customerFiles);
            int isChangedFile = db.SaveChanges();

            if (isChanged > 0 && isChangedFile > 0)
            {
                return(true);
            }
            return(false);
        }
        public ActionResult Add(Customer customer)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (customer.UploadFiles != null && customer.UploadFiles[0] != null)
                    {
                        var customerFiles = new List <CustomerFiles>();
                        foreach (var uploadFile in customer.UploadFiles)
                        {
                            var customerFile = new CustomerFiles();
                            var fileByte     = new byte[uploadFile.ContentLength];
                            uploadFile.InputStream.Read(fileByte, 0, uploadFile.ContentLength);
                            customerFile.File     = fileByte;
                            customerFile.FileName = uploadFile.FileName;

                            customerFiles.Add(customerFile);
                        }

                        customer.CustomerFiles = customerFiles;
                    }

                    if (GetDuplicateCustomer(customer.Code) == false)
                    {
                        var isAdded = _customerManager.Add(customer);
                        if (isAdded)
                        {
                            ViewBag.SMsg = "Save Successfully";
                        }

                        else
                        {
                            ViewBag.FMsg = "Save Failed";
                        }
                    }
                    else
                    {
                        ViewBag.DMsg = "Customer with this Code already exists";
                    }
                }
            }
            catch (Exception e)
            {
                ViewBag.FMsg = e.Message;
            }

            return(View());
        }
        public ActionResult Delete(int id, int idFile)
        {
            bool          isDeleted     = false;
            Customer      customer      = _customerManager.GetCustomerById(id);
            CustomerFiles customerFiles = _customerManager.GetCustomerFilesById(idFile);

            if (customer != null)
            {
                isDeleted = _customerManager.Delete(customer, customerFiles);
            }
            if (isDeleted)
            {
                TempData["SMsg"] = "Deleted Successfully";
            }
            TempData["FMsg"] = "Not Deleted";
            return(RedirectToAction("Show"));
        }
Beispiel #4
0
        public ActionResult CustomerCreate(Customer customer)
        {
            DefaultLoad();
            try
            {
                if (customer.UploadFiles != null && customer.UploadFiles[0] != null)
                {
                    var customerFiles = new List <CustomerFiles>();
                    foreach (var uploadFile in customer.UploadFiles)
                    {
                        var customerFile = new CustomerFiles();
                        var fileByte     = new byte[uploadFile.ContentLength];
                        uploadFile.InputStream.Read(fileByte, 0, uploadFile.ContentLength);
                        customerFile.File     = fileByte;
                        customerFile.FileName = uploadFile.FileName;

                        customerFiles.Add(customerFile);
                    }

                    customer.CustomerFileses = customerFiles;
                }

                bool isSave = false;
                isSave = _cuManager.SaveCustomer(customer);
                if (isSave)
                {
                    ViewBag.SMsg = "Student Add Successfully!!";
                }
                else
                {
                    ViewBag.FMsg = "Student Add Failed!!";
                }
            }
            catch (Exception ex)
            {
                ViewBag.FMsg = ex.Message;
            }
            //ViewBag.SubDistrictId = new SelectList(_db.SubDistricts, "Id", "Name", student.SubDistrictId);
            return(View(customer));
        }
        public CustomerFiles GetCustomerFilesById(int id)
        {
            CustomerFiles customerFiles = _customerRepository.GetCustomerFilesById(id);

            return(customerFiles);
        }
        public bool Delete(Customer customer, CustomerFiles customerFiles)
        {
            bool isDeleted = _customerRepository.Delete(customer, customerFiles);

            return(isDeleted);
        }
Beispiel #7
0
 public void OnStart()
 {
     BusManager.Send(new SearchBarEvent()
     {
         isShow = true
     });
     querySubscription = BusManager.Add((args) => {
         if (args is SearchBarEvent)
         {
             SearchBarEvent evt = args as SearchBarEvent;
             if (!evt.IsNullOrEmpty())
             {
                 if (evt.isQueryChange)
                 {
                     if (!queryCancel.IsNullOrEmpty())
                     {
                         queryCancel.Dispose();
                         queryCancel = null;
                     }
                     queryCancel = Observable.Return(
                         Regex.IsMatch(evt.queryText, @"([a-zA-Z0-9]{3,}[,\s]*)$", RegexOptions.IgnoreCase)
                         ).Throttle(TimeSpan.FromMilliseconds(500))
                                   .SelectMany(x => {
                         if (x)
                         {
                             return(endpointClient.queryCustomers(evt.queryText));
                         }
                         else
                         {
                             App.Current.Dispatcher.Invoke(() => {
                                 if (!Customers.IsNullOrEmpty())
                                 {
                                     Customers.Clear();
                                 }
                                 if (!CustomerFiles.IsNullOrEmpty())
                                 {
                                     CustomerFiles.Clear();
                                 }
                             });
                         }
                         return(Observable.Empty <HttpResponseMessage>());
                     }).ToResponse <List <CustomerEntity> >()
                                   .SubscribeOn(ThreadPoolScheduler.Instance)
                                   .ObserveOn(App.Current.Dispatcher)
                                   .Subscribe(x => {
                         if (x.Code == ResponseCode.OK)
                         {
                             List <CustomerEntity> customers = x.Data;
                             if (!customers.IsNullOrEmpty())
                             {
                                 if (Customers.IsNullOrEmpty())
                                 {
                                     Customers = new CustomerEntities();
                                 }
                                 else
                                 {
                                     Customers.Clear();
                                     if (!CustomerFiles.IsNullOrEmpty())
                                     {
                                         CustomerFiles.Clear();
                                     }
                                 }
                                 customers.ForEach(y => Customers.Add(y));
                             }
                         }
                         else
                         {
                             x.PersistResponseError();
                         }
                     }, error => {
                         error.PersistException();
                         Debug.WriteLine("Error: " + error.StackTrace);
                     }, () => {
                         BusManager.Send(new SearchBarEvent()
                         {
                             isProgress = true
                         });
                     });
                 }
             }
         }
     });
 }
Beispiel #8
0
        public CustomerFiles GetCustomerFilesById(int id)
        {
            CustomerFiles customerFiles = db.CustomerFiles.Where(c => c.Id == id).FirstOrDefault();

            return(customerFiles);
        }