Exemplo n.º 1
0
        public async Task <IActionResult> ItemDetail(int id, int cateId)
        {
            ServiceReference_Item.Item items = await itm.findItembyIdAsync(id);

            ServiceReference_Unit.Unit[] lstUnit = await unit.getAllUnitAsync();

            ServiceReference_Item.Item[] lstRelatedItem = await itm.findItembyCategoryIdAsync(cateId);

            ServiceReference_Feedback.Feedback[] feedbacks = await fb.findFeedbackbyItemIdAsync(id);

            List <RecentViewedItem> lst = new List <RecentViewedItem>();

            byte[] ViewItemsession;
            HttpContext.Session.TryGetValue("RecentProductList", out ViewItemsession);
            string RecentProductList;

            if (ViewItemsession != null)
            {
                RecentProductList = Encoding.UTF8.GetString(ViewItemsession);
                if (RecentProductList == "" || RecentProductList == null)
                {
                    lst = new List <RecentViewedItem>();
                }
                else
                {
                    //convert  string --> lst
                    lst = (List <RecentViewedItem>)JsonConvert.DeserializeObject <List <RecentViewedItem> >(RecentProductList);
                }
            }
            else
            {
                RecentProductList = "";
                lst = new List <RecentViewedItem>();
            }
            // Add product to recent list (make list contain max 3 items; change if you like)
            AddRecentProduct(lst, id, items.ItemName, items.ImageItem, items.Price, items.Unit.UnitName, cateId, 4);

            //luu session;
            RecentProductList = JsonConvert.SerializeObject(lst);
            ViewItemsession   = Encoding.UTF8.GetBytes(RecentProductList);
            HttpContext.Session.Set("RecentProductList", ViewItemsession);

            // Store recentProductList to ViewData keyed as "RecentProductList" to use it in a view
            ViewData["RecentProductList"] = lst;

            CategoryModel iemModel = new CategoryModel
            {
                ItemById           = items,
                listUnit           = lstUnit,
                listItemByCategory = lstRelatedItem,
                lst_feedback       = feedbacks
            };

            ViewBag.ItemId = id;
            return(View(iemModel));
        }
Exemplo n.º 2
0
        // save feedback

        public async Task <JsonResult> SaveFeedback(int itemId, string message)
        {
            ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User);

            _id = await getWholesalerId(user.Email);

            ServiceReference_Item.Item item = await itm.findItembyIdAsync(itemId);

            Feedback feedback = new Feedback();

            feedback.ItemId       = item.ItemId;
            feedback.SubjectFB    = " ";
            feedback.WholesalerId = _id;
            feedback.SupplierId   = item.SupplierId;
            feedback.Message      = message;
            feedback.ReceivedDate = DateTime.Now;
            bool res = await fb.createFeedbackAsync(feedback);

            var lst = await fb.findFeedbackbyItemIdAsync(itemId);

            return(Json(lst));
        }