Ejemplo n.º 1
0
        public ContentResult AddBoss([FromBody] BossViewModel model)
        {
            try
            {
                Boss boss = new Boss()
                {
                    Username = model.UserName,
                    Password = model.Password
                };

                _context.Bosses.Add(boss);
                _context.SaveChanges();
                return(Content("Boss Added"));
            }
            catch (Exception ex)
            {
                return(Content("Error " + ex.Message));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Details()
        {
            try
            {
                var  user       = blUser.Where(p => p.Username == User.Identity.Name).Single();
                bool isRelation = blRelation.Where(p => p.UserId == user.Id).Any();

                if (!isRelation)
                {
                    var model = new BossViewModel()
                    {
                        Trade = null
                    };

                    return(View(model));
                }
                else
                {
                    var tradeId = blRelation.Where(p => p.UserId == user.Id).Single().TradeId;
                    var model   = new BossViewModel()
                    {
                        Trade         = blTrade.Where(p => p.Id == tradeId).Single(),
                        Relations     = blRelation.Where(p => p.TradeId == tradeId && p.UserId != user.Id).ToList(),
                        VehicleGroups = blVehicleGroup.Where(p => p.Status == "فعال").ToList(),
                        Colors        = blColor.Where(p => p.Status == "فعال").ToList(),
                        User          = new User()
                        {
                            Gender = true, Password = "******", ConfirmPassword = "******", RoleId = 5
                        }
                    };

                    return(View(model));
                }
            }
            catch
            {
                return(RedirectToAction("Error404", "Home"));
            }
        }
Ejemplo n.º 3
0
        public ActionResult 銷售數據()
        {
            if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] == null)
            {
                return(RedirectToAction("員工登入", "Employee"));
            }
            MotaiDataEntities   dbContext     = new MotaiDataEntities();
            List <tFavorite>    tFavorites    = dbContext.tFavorites.ToList();
            List <tOrderDetail> tOrderDetails = dbContext.tOrderDetails.ToList();
            var favorOrder = (from i in tFavorites
                              group i by new {
                i.fProductId,
                i.tProduct.pName,
                i.tProduct.tProductCategory.Category,
            } into j
                              select new
            {
                Pid = j.Key.fProductId,
                Pcount = j.Count(),
                Pname = j.Key.pName,
                Pcategory = j.Key.Category
            }).OrderByDescending(j => j.Pcount).ToList();
            var buyOrder = (from i in tOrderDetails
                            group i by new
            {
                i.oProductId,
                i.tProduct.pName,
                i.tProduct.tProductCategory.Category,
            } into j
                            select new
            {
                Pid = j.Key.oProductId,
                Pcount = j.Sum(p => p.oProductQty),
                Pname = j.Key.pName,
                Pcategory = j.Key.Category
            }).OrderByDescending(j => j.Pcount).ToList();
            BossViewModel         boss   = new BossViewModel();
            List <favorViewModel> favorV = new List <favorViewModel>();
            List <buyViewModel>   buyV   = new List <buyViewModel>();

            foreach (var item in favorOrder)
            {
                favorViewModel favor  = new favorViewModel();
                tProduct       p      = new tProduct();
                List <string>  pimage = new List <string>();
                p.ProductId = item.Pid;
                pimage      = productRespotiory.GetProductShowImages(p);
                if (pimage.Count > 0)
                {
                    favor.epsImage = Url.Content(pimage[0]);
                }
                else
                {
                    favor.epsImage = "";
                }
                favor.faverCount = item.Pcount;
                favor.psCategory = item.Pcategory;
                favor.pName      = item.Pname;
                favorV.Add(favor);
            }
            foreach (var item in buyOrder)
            {
                buyViewModel  buy    = new buyViewModel();
                tProduct      p      = new tProduct();
                List <string> pimage = new List <string>();
                p.ProductId = item.Pid;
                pimage      = productRespotiory.GetProductShowImages(p);
                if (pimage.Count > 0)
                {
                    buy.epsImage = Url.Content(pimage[0]);
                }
                else
                {
                    buy.epsImage = "";
                }
                buy.buyCount   = item.Pcount;
                buy.psCategory = item.Pcategory;
                buy.pName      = item.Pname;
                buyV.Add(buy);
            }

            boss.buyV   = buyV;
            boss.favorV = favorV;

            return(View(boss));
        }