Exemplo n.º 1
0
        public ActionResult News(HomeViewModel homeViewModel, HttpPostedFileBase image)
        {
            DbCenter.ModelClasses.Photo photoreturned = null;
            if (image != null)
            {
                string path = Path.Combine(Server.MapPath("~/assets/Uploaded_photos"), Path.GetFileName(image.FileName));
                image.SaveAs(path);

                DbCenter.ModelClasses.Photo photo = new DbCenter.ModelClasses.Photo();
                photo.URL     = "assets/Uploaded_photos/" + image.FileName;
                photoreturned = ESaleContext.AddPhoto(photo);
            }

            var post = new DbCenter.ModelClasses.Post();

            post.UserID       = (int)Session["UserID"];
            post.Text         = homeViewModel.Text;
            post.CreationDate = DateTime.Now;

            if (image != null)
            {
                post.PhotoID = photoreturned.ID;
            }
            else
            {
                post.PhotoID = null;
            }

            ESaleContext.AddPost(post);
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
0
        public ActionResult News(NewsViewModel NewsViewModel, HttpPostedFileBase image)
        {
            DbCenter.ModelClasses.Photo photoreturned = null;
            if (image != null)
            {
                string path = Path.Combine(Server.MapPath("~/assets/Uploaded_photos"), Path.GetFileName(image.FileName));
                image.SaveAs(path);

                DbCenter.ModelClasses.Photo photo = new DbCenter.ModelClasses.Photo();
                photo.URL     = "assets/Uploaded_photos/" + image.FileName;
                photoreturned = ESaleContext.AddPhoto(photo);
            }
            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <NewsViewModel, DbCenter.ModelClasses.Post>()
                .ForMember(dst => dst.Company, src => src.Ignore());
            });

            var post = Mapper.Map <DbCenter.ModelClasses.Post>(NewsViewModel);

            post.CompanyID = (int)Session["CompanyID"];
            if (image != null)
            {
                post.PhotoID = photoreturned.ID;
            }
            else
            {
                post.PhotoID = null;
            }
            post.CreationDate = DateTime.Now;

            ESaleContext.AddPost(post);


            return(RedirectToAction("News", new { id = post.CompanyID }));
        }
Exemplo n.º 3
0
        public ActionResult Product(ProductViewModel ProductViewModel, HttpPostedFileBase image)
        {
            string path = Path.Combine(Server.MapPath("~/assets/Uploaded_photos"), Path.GetFileName(image.FileName));

            image.SaveAs(path);

            DbCenter.ModelClasses.Photo photo = new DbCenter.ModelClasses.Photo();
            photo.URL = "assets/Uploaded_photos/" + image.FileName;
            var photoreturned = ESaleContext.AddPhoto(photo);

            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <DbCenter.ModelClasses.Company, Models.MVCCompany>();
                cfg.CreateMap <Models.MVCCompany, DbCenter.ModelClasses.Company>();
                cfg.CreateMap <ProductViewModel, DbCenter.ModelClasses.Product>();
            });
            var product = Mapper.Map <DbCenter.ModelClasses.Product>(ProductViewModel);

            product.CompanyID = (int)Session["CompanyID"];
            product.PhotoID   = photoreturned.ID;
            ESaleContext.AddProduct(product);

            return(RedirectToAction("Product"));
        }