Beispiel #1
0
        public IActionResult AddUser(UserModel userModel)
        {
            using (var context = new FollowUpDbContext())
            {
                Employee employee = _mapper.Map <Employee>(userModel.Employee);
                User     user     = _mapper.Map <User>(userModel.User);

                context.Employee.Add(employee);
                context.SaveChanges();
                user.Empid    = employee.Id;
                user.Username = employee.Email;
                user.IsActive = true;
                user.IsDelete = false;
                user.Type     = userModel.User.type.ToString();
                context.User.Add(user);
                int a = context.SaveChanges();
                if (a > 0)
                {
                    userModel = null;
                }
            }
            ViewBag.Name  = HttpContext.Session.GetString(SessionName);
            ViewBag.Title = "User";
            return(View());
        }
Beispiel #2
0
        public IActionResult Index(UserResultViewModel UserReult)
        {
            ViewBag.Name  = HttpContext.Session.GetString(SessionName);
            ViewBag.Title = "User";
            UserResultViewModel _userResultViewModels = new UserResultViewModel();

            _userResultViewModels.SearchDate = new SearchModel();
            //Get Customer Details
            _userResultViewModels.UserResultviewCustomer = new List <CustomerFollowUp>();
            int SalesPersonId = Convert.ToInt32(HttpContext.Session.GetString(SessionId));
            //int SalesPersonId = 2;
            string   Curr_date = System.DateTime.Now.ToShortDateString();
            DateTime Cur_date  = Convert.ToDateTime(Curr_date);

            if (UserReult.SearchDate != null)
            {
                _userResultViewModels.UserResultviewCustomer = _followupsContext.CustomerFollowUp.Where(x => x.DateOfContact >= UserReult.SearchDate.FromDate && x.DateOfContact <= UserReult.SearchDate.ToDate || x.CreateDate >= Cur_date && x.SalesPersonId == SalesPersonId).ToList();
                _userResultViewModels.CountryResult          = new List <Countries>();
                _userResultViewModels.CountryResult          = (from d in _followupsContext.Countries select d).ToList();
                _userResultViewModels.CountryResult.Insert(0, new Countries {
                    Id = 0, Name = "--Select--"
                });
                ViewBag.Country = _userResultViewModels.CountryResult;
                //Bind Sales Person
                _userResultViewModels.ResultSalesPerson = new List <Employee>();
                _userResultViewModels.ResultSalesPerson = (from c in _followupsContext.Employee select c).ToList();
                _userResultViewModels.ResultSalesPerson.Insert(0, new Employee {
                    Id = 0, Name = "--Select--"
                });
                ViewBag.SalesPerson = _userResultViewModels.ResultSalesPerson;
            }
            else
            {
                if (UserReult.UserResultviewCustomer != null)
                {
                    foreach (var item in UserReult.UserResultviewCustomer)
                    {
                        CustomerFollowUp objCust = new CustomerFollowUp();
                        objCust                  = _followupsContext.CustomerFollowUp.Find(item.FollowId);
                        objCust.CountryId        = item.CountryId;
                        objCust.CustomerInterest = item.CustomerInterest;
                        objCust.DateOfContact    = item.DateOfContact;
                        objCust.Idstatus         = item.Idstatus;
                        objCust.Phone            = objCust.Phone;
                        objCust.SalesPersonId    = objCust.SalesPersonId;
                        string   d        = DateTime.Now.ToShortDateString();
                        DateTime cur_date = Convert.ToDateTime(d);
                        objCust.ModifiedDate = cur_date;
                        _followupsContext.Entry(objCust).State = EntityState.Modified;
                        _followupsContext.SaveChanges();
                    }
                }
            }
            //Bind Country

            return(View(_userResultViewModels));
        }
Beispiel #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"));
            }
        }