public ActionResult toProfile(int idSwapper)
        {
            swapper user = service.Get(u => u.id_swapper == idSwapper);

            ViewBag.user = user;
            if (user.imgPath == null)
            {
                user.imgPath = "";
            }
            if (user.imgPath.Equals("") && user.sex == Sex.M)
            {
                ViewBag.imgPath = "~/imgs/man.gif";
            }
            else if (user.imgPath.Equals("") && user.sex == Sex.F)
            {
                ViewBag.imgPath = "~/imgs/female.png";
            }
            else
            {
                ViewBag.imgPath = user.imgPath;
            }

            return(View());
        }
        public ActionResult renderAddGoods()
        {
            int connectedSwapper = 1; // identity connected user

            swapper user = swapperService.Get(u => u.id_swapper == connectedSwapper);

            ViewBag.user = user;

            IEnumerable <category> categories = categoryService.GetAll();

            category cat = categories.First();
            IEnumerable <subCategory> subCategories = subCategoryService.GetMany(s => s.categoryID == cat.id_category);

            ViewBag.categories    = categories;
            ViewBag.subCategories = subCategories;

            return(View());
        }
        public ActionResult SaveMyGood(GoodModels GM)
        {
            System.Diagnostics.Debug.WriteLine("------------------------------------   :    " + GM.goood.id_goods);


            service = new GoodService();

            swapperService     = new SwapperService();
            categoryService    = new CategoryService();
            subCategoryService = new SubCategoryService();


            int connectedSwapper = 1;

            swapper user = swapperService.Get(u => u.id_swapper == connectedSwapper);

            ViewBag.user = user;


            string   brand       = Request.Form["brand"];
            string   description = Request.Form["desc"];
            DateTime date        = DateTime.Now;
            int      validity    = 0;
            int      quantity    = int.Parse(Request.Form["quantity"]);
            string   label       = Request.Form["label"];

            int idGood = int.Parse(Request.Form["idGood"]);

            Accpted accepted = Accpted.no;

            int catId = int.Parse(Request.Form["cat"]);
            //category cat = categoryService.Get(c => c.id_category == catId);

            int subCatId = int.Parse(Request.Form["subCat"]);

            //subCategory subCat = subCategoryService.Get(sc => sc.id_subCategory == subCatId);

            GM.goood             = service.GetById(idGood);
            GM.goood.label       = label;
            GM.goood.brand       = brand;
            GM.goood.description = description;
            GM.goood.date        = date;
            GM.goood.validity    = validity;
            GM.goood.quantity    = quantity;
            GM.goood.accepted    = accepted;

            //subCat.category = cat;

            GM.goood.subCategoryID = subCatId;
            GM.goood.swapperID     = user.id_swapper;

            service.Update(GM.goood);
            service.Commit();



            if (Request.Files[0].ContentLength > 0)
            {
                byte[] file = null;
                using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
                {
                    file = binaryReader.ReadBytes(Request.Files[0].ContentLength);
                }


                Image img = this.byteArrayToImage(file);
                img = new Bitmap(img, new Size(180, 180));

                string path = "~/swapperImgs/" + GM.goood.id_goods + ".jpg";
                img.Save(Server.MapPath(path), System.Drawing.Imaging.ImageFormat.Jpeg);

                GM.goood.image = path;
                service.Update(GM.goood);
                service.Commit();
            }

            return(RedirectToAction("SearchMyGood"));
        }
        public ActionResult addGoods()
        {
            service = new GoodService();

            swapperService     = new SwapperService();
            categoryService    = new CategoryService();
            subCategoryService = new SubCategoryService();


            int connectedSwapper = 1; // connected swapper -identity

            swapper user = swapperService.Get(u => u.id_swapper == connectedSwapper);

            ViewBag.user = user;


            string   brand       = Request.Form["brand"];
            string   description = Request.Form["desc"];
            DateTime date        = DateTime.Now;
            int      validity    = 0;
            int      quantity    = int.Parse(Request.Form["quantity"]);
            string   label       = Request.Form["label"];
            Accpted  accepted    = Accpted.no;

            int catId = int.Parse(Request.Form["cat"]);
            //category cat = categoryService.Get(c => c.id_category == catId);

            int subCatId = int.Parse(Request.Form["subCat"]);
            //subCategory subCat = subCategoryService.Get(sc => sc.id_subCategory == subCatId);

            goods newGood = new goods();

            newGood.label       = label;
            newGood.brand       = brand;
            newGood.description = description;
            newGood.date        = date;
            newGood.validity    = validity;
            newGood.quantity    = quantity;
            newGood.accepted    = accepted;

            //subCat.category = cat;

            newGood.subCategoryID = subCatId;
            newGood.swapperID     = user.id_swapper;
            service.Add(newGood);
            service.Commit();



            if (Request.Files[0].ContentLength > 0) // on a ajouté une image pour le produit
            {
                byte[] file = null;
                using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
                {
                    file = binaryReader.ReadBytes(Request.Files[0].ContentLength);
                }


                Image img = this.byteArrayToImage(file);
                img = new Bitmap(img, new Size(180, 180));

                string path = "~/swapperImgs/" + newGood.id_goods + ".jpg";
                img.Save(Server.MapPath(path), System.Drawing.Imaging.ImageFormat.Jpeg);


                newGood.image = path;
                service.Update(newGood);
                service.Commit();
            }



            return(RedirectToAction("SearchGood"));
        }