public ActionResult Create(PublicationVM PublicationVM, HttpPostedFileBase Image)
        {
            Publication PublicationDomain = new Publication();


            PublicationDomain.title        = PublicationVM.title;
            PublicationDomain.creationDate = DateTime.UtcNow;
            PublicationDomain.description  = PublicationVM.description;
            PublicationDomain.visibility   = (Visibility)PublicationVM.visibility;
            PublicationDomain.image        = Image.FileName;
            PublicationDomain.nomuser      = "******";                               //User.Identity.GetUserName();
            PublicationDomain.OwnerId      = "f43c21cf-f35a-4897-a9e3-343c00afe7b4"; //User.Identity.GetUserId();
            PublicationDomain.ownerimg     = "exp.png";                              // MyUser.GetById(User.Identity.GetUserId()).image;



            pubserv.Add(PublicationDomain);
            //notifserv.Add(comp2);
            pubserv.Commit();


            var path = Path.Combine(Server.MapPath("~/Content/Uploads"), Image.FileName);

            Image.SaveAs(path);
            return(RedirectToAction("Index"));
        }
Пример #2
0
        public Publication Post(Publication proj)
        {
            MyService.Add(proj);
            MyService.Commit();

            return(proj);
        }
        public ActionResult Create(PublicationVM publicationvm, HttpPostedFileBase file)
        {
            if (!ModelState.IsValid || file == null || file.ContentLength == 0)
            {
                RedirectToAction("Create");
            }

            Publication PublicationDomain = new Publication()
            {
                datePub        = DateTime.Today,
                imagePub       = file.FileName,
                nbLike         = publicationvm.nbLike,
                nbDislike      = publicationvm.nbDislike,
                titlePub       = publicationvm.titlePub,
                descriptionPub = publicationvm.descriptionPub,
                Dislike        = publicationvm.Dislike,
                Like           = publicationvm.Like,
                ParentFk       = (int)Session["idu"],
            };

            Service.Add(PublicationDomain);
            Service.Commit();
            var fileName = "";

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

            return(RedirectToAction("Index"));
        }