// GET: Offer/Details/5
        public ActionResult Details(int id)
        {
            IEnumerable <Company> companies = CService.GetMany().ToList();

            ViewBag.data = companies;
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Offer   o   = OService.GetById(id);
            OfferVM ovm = new OfferVM()
            {
                OfferId                  = o.OfferId,
                Offer_Title              = o.Offer_Title,
                Offer_description        = o.Offer_description,
                Offre_Duration           = o.Offre_Duration,
                Offre_Salary             = o.Offre_Salary,
                Offer_Contract_Type      = (ContractTypeVM)o.Offer_Contract_Type,
                Offer_Level_Of_Expertise = (OfferLevelVM)o.Offer_Level_Of_Expertise,
                Offer_DatePublished      = o.Offer_DatePublished,
                Vues      = o.Vues,
                CompanyId = o.CompanyId
            };

            o.Vues = o.Vues + 1;
            OService.Update(o);
            OService.Commit();
            if (o == null)
            {
                return(HttpNotFound());
            }
            return(View(ovm));
        }
Exemple #2
0
        public ActionResult Create(OfferVm ovm, HttpPostedFileBase file)
        {
            if (
                file == null ||
                file.ContentLength == 0)
            {
                return(RedirectToAction("Create"));
            }


            Offer offerdomain = new Offer()
            {
                StartDate   = ovm.StartDate,
                OfferName   = ovm.OfferName,
                Price       = ovm.Price,
                EndDate     = ovm.EndDate,
                ProductId   = ovm.ProductId,
                Description = ovm.Description,
                ImgUrl      = file.FileName,
            };

            service.Add(offerdomain);
            service.Commit();


            var path = "";
            //ajout d'image sous dossier
            var fileName = "";

            if (file.ContentLength > 0)
            {
                fileName = Path.GetFileName(file.FileName);
                path     = Path.
                           Combine(Server.MapPath("~/Content/Uploads/"),
                                   fileName);
                file.SaveAs(path);
            }
            var path2 = path;

            return(RedirectToAction("Index"));
        }