예제 #1
0
        private CustomerResultViewModel GetCustomers(int currentPage)
        {
            int maxRows = 10;
            CustomerResultViewModel customerModel = new CustomerResultViewModel();

            customerModel.ResultCustomer = new List <Customer>();
            var result = (from customer in this._followupsContext.CustomerFollowUp
                          select customer)
                         .OrderBy(customer => customer.FollowId)
                         .Skip((currentPage - 1) * maxRows)
                         .Take(maxRows).ToList();

            double pageCount = (double)((decimal)this._followupsContext.CustomerFollowUp.Count() / Convert.ToDecimal(maxRows));

            customerModel.custPageNumber = (int)Math.Ceiling(pageCount);

            customerModel.ResultCustomer        = _mapper.Map <List <CustomerFollowUp>, List <Customer> >(result);
            customerModel.custCurrentPageNumber = currentPage;

            return(customerModel);
        }
예제 #2
0
        public IActionResult Index()
        {
            ViewBag.Name  = HttpContext.Session.GetString(SessionName);
            ViewBag.Title = "Admin";
            CustomerResultViewModel _custResult = new CustomerResultViewModel();

            _custResult.ResultCustomer    = new List <Customer>();
            _custResult.ResultSalesPerson = new List <Employee>();
            _custResult.Customer          = new Customer();
            _custResult.ResultSalesPerson = (from c in _followupsContext.Employee select c).ToList();
            _custResult.ResultSalesPerson.Insert(0, new Employee {
                Id = 0, Name = "--Select--"
            });
            ViewBag.SalesPerson = _custResult.ResultSalesPerson;

            //Coutry Details
            _custResult.ResultCountry = new List <Countries>();
            _custResult.ResultCountry = (from d in _followupsContext.Countries select d).ToList();
            _custResult.ResultCountry.Insert(0, new Countries {
                PhoneCode = 0, Name = "--Select--"
            });
            ViewBag.Country = _custResult.ResultCountry;
            return(View(_custResult));
        }
예제 #3
0
        public IActionResult Index(CustomerResultViewModel customers, IFormFile file, [FromServices] IHostingEnvironment hostingEnvironment)
        {
            CustomerResultViewModel _custResult = new CustomerResultViewModel();

            _custResult.ResultCustomer    = new List <Customer>();
            _custResult.ResultSalesPerson = new List <Employee>();
            _custResult.Customer          = new Customer();
            //Sales Persons Details
            _custResult.ResultSalesPerson = (from c in _followupsContext.Employee select c).ToList();
            _custResult.ResultSalesPerson.Insert(0, new Employee {
                Id = 0, Name = "--Select--"
            });
            ViewBag.SalesPerson = _custResult.ResultSalesPerson;

            //Coutry Details
            _custResult.ResultCountry = new List <Countries>();
            _custResult.ResultCountry = (from d in _followupsContext.Countries select d).ToList();
            _custResult.ResultCountry.Insert(0, new Countries {
                PhoneCode = 0, Name = "--Select--"
            });
            ViewBag.Country = _custResult.ResultCountry;

            //Upload Files
            if (file != null)
            {
                int    Countrycode = (int)customers.Customer.CountryId;
                string filename    = $"{hostingEnvironment.WebRootPath}\\files\\{ file.FileName}";
                using (FileStream fileStream = System.IO.File.Create(filename))
                {
                    file.CopyTo(fileStream);
                    fileStream.Flush();
                }
                _custResult.ResultCustomer = this.GetCustDetails(file.FileName, Countrycode);
                return(View(_custResult));
            }
            //Save Details
            else
            {
                DataTable dtUnassigned = new DataTable();
                dtUnassigned.Columns.Add("Phone", typeof(string));
                if (customers.ResultCustomer != null)
                {
                    using (var context = new FollowUpDbContext())
                    {
                        foreach (var item in customers.ResultCustomer)
                        {
                            if (item.SalesPersonId != 0)
                            {
                                CustomerFollowUp CustResult = _mapper.Map <CustomerFollowUp>(item);
                                context.CustomerFollowUp.Add(CustResult);
                                context.SaveChanges();
                            }
                            else
                            {
                                dtUnassigned.Rows.Add(item.Phone);
                            }
                        }
                    }
                    if (dtUnassigned.Rows.Count > 0)
                    {
                        string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                        string fileName    = "UnAssignedPhone.xlsx";
                        using (var workbook = new XLWorkbook())
                        {
                            IXLWorksheet worksheet =
                                workbook.Worksheets.Add("Sheet1");
                            worksheet.Cell(1, 1).Value = "Phone";
                            for (int i = 0; i <= dtUnassigned.Rows.Count - 1; i++)
                            {
                                worksheet.Cell(i + 1, 1).Value = dtUnassigned.Rows[i]["Phone"].ToString();
                            }
                            using (var stream = new MemoryStream())
                            {
                                workbook.SaveAs(stream);
                                var content = stream.ToArray();
                                return(File(content, contentType, fileName));
                            }
                        }
                    }
                }
                //Save Details Mannually
                if (customers.Customer != null)
                {
                    string   d1       = DateTime.Now.ToShortDateString();
                    DateTime Cur_date = Convert.ToDateTime(d1);
                    _custResult.Customer.CreateDate = Cur_date;
                    customers.Customer.CreateDate   = Cur_date;
                    var details = customers.Customer;

                    CustomerFollowUp CustResult = _mapper.Map <CustomerFollowUp>(customers.Customer);
                    _followupsContext.CustomerFollowUp.Add(CustResult);
                    _followupsContext.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
        }