Exemplo n.º 1
0
        public List <ItemModelview> GetMyTrade(string username)
        {
            var ImageStorerepo = new ImageStoreService();
            var Itemrepo       = new ItemService();
            List <ItemModelview> lstItemModelview = new List <ItemModelview>();
            var lstimgId = ImageStorerepo.GetAll().FindAll(x => x.UserName.Equals(username)).Select(w => w.imgId);

            List <string> lstItemref = new List <string>();

            foreach (var item in lstimgId)
            {
                string x = item.Substring(0, item.Length - 1);
                if (!lstItemref.Contains(x))
                {
                    lstItemref.Add(x);
                }
            }
            foreach (var item in lstItemref)
            {
                var           _item          = Itemrepo.GetById(item);
                ItemModelview _ItemModelview = new ItemModelview
                {
                    ItemName        = _item.ItemName,
                    ItemPrice       = _item.ItemPrice,
                    ItemDescription = _item.ItemDescription,
                    ItemRef         = _item.ItemRef,
                    src             = ImageStorerepo.GetById(item + "0").imgByte
                };
                lstItemModelview.Add(_ItemModelview);
            }
            return(lstItemModelview);
        }
Exemplo n.º 2
0
        public ItemModelview DetailsItemApp(string id)
        {
            var           ImageStorerepo = new ImageStoreService();
            List <byte[]> lst            = new List <byte[]>();

            using (var Itemrepo = new ItemService())
            {
                string        itemid         = id + "0";
                ItemModelview _ItemModelview = new ItemModelview();

                if (!id.Equals(string.Empty))
                {
                    //find the item in item table
                    var item = Itemrepo.GetAll().Find(x => x.ItemRef.Equals(id));
                    _ItemModelview.ItemName  = item.ItemName;
                    _ItemModelview.ItemPrice = item.ItemPrice;
                    //find client username in the storeImage table
                    _ItemModelview.UserName        = ImageStorerepo.GetById(itemid).UserName;
                    _ItemModelview.ItemDescription = item.ItemDescription;
                    _ItemModelview.ItemRef         = id;
                    _ItemModelview.date            = ImageStorerepo.GetById(itemid).date;
                    foreach (var img in GetAllImage())
                    {
                        if (img.imgId.Substring(0, img.imgId.Length - 1).Equals(id))
                        {
                            lst.Add(img.imgByte);
                        }
                    }
                    _ItemModelview.Lstsrc = lst;
                }
                return(_ItemModelview);
            }
        }
Exemplo n.º 3
0
 public IHttpActionResult Edit(ItemModelview model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _ItemBusiness.PostEditItem(model);
     return(Ok());
 }
Exemplo n.º 4
0
 public IHttpActionResult Create(ItemModelview model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     model.UserName = ClaimsPrincipal.Current.Identity.Name;;
     _ItemBusiness.CreateItem(model);
     return(Ok());
 }
Exemplo n.º 5
0
        // this is method is the same with the find
        public ItemModelview GetEditItem(string id)
        {
            ItemModelview _ItemModelview = new ItemModelview();

            using (var repo = new ItemService())
            {
                var item = repo.GetById(id);
                _ItemModelview.ItemName        = item.ItemName;
                _ItemModelview.ItemPrice       = item.ItemPrice;
                _ItemModelview.ItemRef         = item.ItemRef;
                _ItemModelview.ItemDescription = item.ItemDescription;

                return(_ItemModelview);
            }
        }
Exemplo n.º 6
0
        public void PostEditItem(ItemModelview model)
        {
            using (var repo = new ItemService())
            {
                var Itemtopdate = repo.GetById(model.ItemRef);
                Itemtopdate = new Item
                {
                    ItemName        = model.ItemName,
                    ItemPrice       = model.ItemPrice,
                    ItemDescription = model.ItemDescription
                };


                _ImageStoreBusiness.PostEdit(model);
                repo.Update(Itemtopdate);
            }
        }
Exemplo n.º 7
0
        public bool DeleteItem(string id)
        {
            ItemModelview _ItemModelview = new ItemModelview();

            using (var repo = new ItemService())
            {
                try
                {
                    var item = repo.GetById(id);
                    _ImageStoreBusiness.DeleteAllImage(id);
                    repo.Delete(item);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 8
0
 public void CreateImageForItem(ItemModelview model)
 {
     using (var ImageStorerepo = new ImageStoreService())
     {
         int count = 0;
         // from the website
         if (model.ImageFile != null)
         {
             foreach (var file in model.ImageFile)
             {
                 byte[]       imgbyte = null;
                 BinaryReader reader  = new BinaryReader(file.InputStream);
                 imgbyte = reader.ReadBytes(file.ContentLength);
                 ImageStore img = new ImageStore
                 {
                     imgId    = model.ItemRef + count,
                     UserName = model.UserName,
                     ItemName = model.ItemName,
                     date     = DateTime.Now,
                     imgByte  = imgbyte
                 };
                 ImageStorerepo.Insert(img);
                 count++;
             }
         }
         // from app
         else
         {
             ImageStore img = new ImageStore
             {
                 imgId    = model.ItemRef + count,
                 UserName = model.UserName,
                 ItemName = model.ItemName,
                 date     = DateTime.Now,
                 imgByte  = model.src
             };
             ImageStorerepo.Insert(img);
         }
     }
 }
Exemplo n.º 9
0
        public ItemModelview DetailsItem(string id)
        {
            var ImageStorerepo = new ImageStoreService();

            using (var Itemrepo = new ItemService())
            {
                string        itemid         = id + "0";
                ItemModelview _ItemModelview = new ItemModelview();
                if (!id.Equals(""))
                {
                    //find the item in item table
                    var item = Itemrepo.GetAll().Find(x => x.ItemRef.Equals(id));
                    _ItemModelview.ItemName  = item.ItemName;
                    _ItemModelview.ItemPrice = item.ItemPrice;
                    //find client username in the storeImage table
                    _ItemModelview.UserName        = ImageStorerepo.GetById(itemid).UserName;
                    _ItemModelview.ItemDescription = item.ItemDescription;
                    _ItemModelview.ItemRef         = id;
                }
                return(_ItemModelview);
            }
        }
Exemplo n.º 10
0
        public void CreateItem(ItemModelview model)
        {
            #region Create a ref number of the item
            string word      = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            Random rd        = new Random();
            int    num1      = rd.Next(-1, 24);
            string StampDate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString();
            model.ItemRef = word.Substring(num1, 3) + model.ItemName.ToUpper().Substring(0, 1) + StampDate;
            #endregion
            using (var Itemrepo = new ItemService())
            {
                _ImageStoreBusiness.CreateImageForItem(model);

                Item _Item = new Item
                {
                    ItemName        = model.ItemName,
                    ItemPrice       = model.ItemPrice,
                    ItemDescription = model.ItemDescription,
                    ItemRef         = model.ItemRef
                };
                Itemrepo.Insert(_Item);
            }
        }
Exemplo n.º 11
0
        public void PostEdit(ItemModelview model)
        {
            using (var repo = new ImageStoreService())
            {
                // Find all item with the same reference number
                var ImageStore = repo.GetAll().Where(x => x.imgId.Substring(0, x.imgId.Length - 1).Equals(model.ItemRef)).ToList();
                //from website
                if (model.ImageFile != null)
                {
                    //check the number of picture
                    int NumberOfItem = model.ImageFile.Count();
                    if (ImageStore.Count() > NumberOfItem)
                    {
                        //will delete the remaining of ImageStore
                        int count = 0;

                        byte[] imgbyte = null;
                        //update item with new details
                        foreach (var item in ImageStore)
                        {
                            BinaryReader reader = new BinaryReader(model.ImageFile[count].InputStream);
                            imgbyte       = reader.ReadBytes(model.ImageFile[count].ContentLength);
                            item.ItemName = model.ItemName;
                            item.imgByte  = imgbyte;
                            repo.Update(item);
                            count++;
                        }

                        //delete the remainig
                        for (int i = model.ImageFile.Count() + 1; i < ImageStore.Count(); i++)
                        {
                            var ItemToDelete = ImageStore[i];
                            repo.Delete(ItemToDelete);
                        }
                    }
                    else
                    {
                        // will add the remaing of model.ImageFile
                    }
                }
                //from app
                else
                {
                    for (int i = 0; i < model.Lstsrc.Count(); i++)
                    {
                        var itemToUpdate = ImageStore[i];
                        itemToUpdate.ItemName = model.ItemName;
                        itemToUpdate.imgByte  = model.Lstsrc[i];
                        repo.Update(itemToUpdate);
                    }

                    // Delete the remaining item
                    //1 bcz they will be only one pic from app and
                    //the number of img in imageStore must not be one
                    if (model.Lstsrc.Count() == 1 && ImageStore.Count() > 1)
                    {
                        for (int i = 1; i < ImageStore.Count(); i++)
                        {
                            var ItemToDelete = ImageStore[i];
                            repo.Delete(ItemToDelete);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
 public ActionResult Create(ItemModelview model)
 {
     model.UserName = User.Identity.Name;
     _ItemBusiness.CreateItem(model);
     return(RedirectToAction("MyIndex"));
 }