示例#1
0
        public ActionResult SearchModels(Nullable<DateTime> fromDate, Nullable<DateTime> toDate, int? page)
        {
            try
            {
                if (fromDate == null)
                    fromDate = DateTime.Today;
                if (toDate == null)
                    toDate = DateTime.Today;

                var searchResult = from o in db.Models
                                   where o.DtCreated >= fromDate
                                   && o.DtCreated <= toDate
                                   select o;

                var itemList = new List<ModelAdminRetrieveViewModel>();
                foreach (var item in searchResult)
                {
                    var orderItem = new ModelAdminRetrieveViewModel()
                    {
                        ModelId = item.ModelId,
                        ModelNumber = item.ModelNumber,
                        DtCreated = item.DtCreated,
                        Status = item.Status,
                        ImageUrl = (from ph in db.Photos
                                    join pm in db.PhotoModels on ph.PhotoId equals pm.PhotoId
                                    join m in db.Models on pm.ModelId equals m.ModelId
                                    where pm.ModelId == item.ModelId
                                    select ph.ImageUrl).FirstOrDefault(),
                        Price = item.Price,
                        SupplierId = item.SupplierId
                    };
                    itemList.Add(orderItem);
                }
                if (itemList == null)
                {
                    ViewBag.Title = "No Order for in that range found.";
                    return View("RetrieveModels");
                }
                Session["ExcelData"] = itemList;

                //Paging Section
                var pageNumber = page ?? 1; // if no pagenumber is specified in the querystring, it will assign pageNumber to 1 by default
                var pageOfProducts = itemList.ToPagedList(pageNumber, 10); //set the number of records per page
                ViewBag.pageOfProducts = pageOfProducts;

                ViewBag.Title = "List Of Models";

                GetNewSupplierActivation();
                GetNewModelsActivation();
                return View("Retrieve");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
示例#2
0
        public ActionResult ExportToExcel()
        {
            var excelData = Session["ExcelData"] as List<ModelAdminRetrieveViewModel>;
            if (excelData != null)
                _repo.ExportToExcel(excelData);

            Session.Remove("ExcelData");

            if (excelData == null)
            {
                var queryList = db.Models.Where(x => x.Status == "Active").ToList();
                var modelList = new List<ModelAdminRetrieveViewModel>();

                foreach (var item in queryList)
                {
                    var commission = (((from c in db.Commissions
                                        join mc in db.ModelCommissions on c.CommissionId equals mc.CommissionId
                                        where mc.ModelId == item.ModelId
                                        select c.Percentage).FirstOrDefault()));

                    var modelItem = new ModelAdminRetrieveViewModel()
                    {
                        ModelId = item.ModelId,
                        ModelNumber = item.ModelNumber,
                        DtCreated = item.DtCreated,
                        Status = item.Status,
                        ImageUrl = (from ph in db.Photos
                                    join pm in db.PhotoModels on ph.PhotoId equals pm.PhotoId
                                    join m in db.Models on pm.ModelId equals m.ModelId
                                    where pm.ModelId == item.ModelId
                                    select ph.ImageUrl).FirstOrDefault(),
                        Price = item.Price,
                        SupplierId = item.SupplierId,
                        SupplierCommission = Convert.ToInt32((commission * item.Price) / 100),
                        CommissionPercentage = commission + " %",
                        SupplierName = (from s in db.Suppliers
                                        where s.SupplierId == item.SupplierId
                                        select s.Name).FirstOrDefault()
                    };

                    modelList.Add(modelItem);
                }
                _repo.ExportToExcel(modelList);
            }

            return RedirectToAction("RetrieveModels");
        }
示例#3
0
        public ActionResult RetrieveActive(string searchString, ManageMessageId? message, int? page)
        {
            try
            {
                string userId = User.Identity.GetUserId();
                if (userId == null)
                {
                    return RedirectToAction("Login", "Account");
                }

                if (User.IsInRole("Admin"))
                {
                    var records = db.Models.Where(x => x.Status == "Active").ToList();
                    var modelList = new List<ModelAdminRetrieveViewModel>();

                    foreach (var item in records)
                    {
                        var commission = (((from c in db.Commissions
                                            join mc in db.ModelCommissions on c.CommissionId equals mc.CommissionId
                                            where mc.ModelId == item.ModelId
                                            select c.Percentage).FirstOrDefault()));

                        var modelItem = new ModelAdminRetrieveViewModel()
                        {
                            ModelId = item.ModelId,
                            ModelNumber = item.ModelNumber,
                            DtCreated = item.DtCreated,
                            Status = item.Status,
                            ImageUrl = (from ph in db.Photos
                                        join pm in db.PhotoModels on ph.PhotoId equals pm.PhotoId
                                        join m in db.Models on pm.ModelId equals m.ModelId
                                        where pm.ModelId == item.ModelId
                                        select ph.ImageUrl).FirstOrDefault(),
                            Price = item.Price,
                            SupplierId = item.SupplierId,
                            SupplierCommission = Convert.ToInt32((commission * item.Price) / 100),
                            CommissionPercentage = commission + " %",
                            SupplierName = (from s in db.Suppliers
                                            where s.SupplierId == item.SupplierId
                                            select s.Name).FirstOrDefault()
                        };
                        if (!String.IsNullOrWhiteSpace(searchString))
                        {
                            var properString = helper.ConvertToTitleCase(searchString);
                            if (modelItem.SupplierName == properString)
                            {
                                modelList.Add(modelItem);
                            }
                        }
                        if (String.IsNullOrWhiteSpace(searchString))
                        {
                            modelList.Add(modelItem);
                        }
                    }

                    //if (records == null)
                    //{
                    //    return HttpNotFound();
                    //}

                    ViewBag.StatusMessage =
                message == ManageMessageId.AddSuccess ? "You have successfully added a new Model."
                : message == ManageMessageId.ArchiveSuccess ? "You have just archive a Model."
                : message == ManageMessageId.UpdateSuccess ? "You have successfully activated a Model."
                : message == ManageMessageId.RestoreSuccess ? "You have successfully restore a Model."
                : message == ManageMessageId.Error ? "An error has occurred."
                : "";

                    //Paging Section
                    var pageNumber = page ?? 1; // if no pagenumber is specified in the querystring, it will assign pageNumber to 1 by default
                    var pageOfProducts = modelList.OrderByDescending(x => x.Status).ToPagedList(pageNumber, 10); //set the number of records per page
                    ViewBag.pageOfProducts = pageOfProducts;

                    GetNewSupplierActivation();
                    GetNewModelsActivation();
                    return View();
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }