public IActionResult Index(Guid?id)
        {
            var   userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            Owner Owner  = null;

            if (id != null)
            {
                Owner = _uow.GetPortofolio(id);
            }
            else
            {
                if (userId != "" && userId != null)
                {
                    Owner = _uow.GetPortofolioByUser(new Guid(userId));
                }
            }
            if (Owner == null)
            {
                Owner = _uow.OwnerRepository.GetDefaultOwner();//.GetFirstOwnerWithAddress();
            }
            var portofolioItems = _uow.PortofolioItemRepository.GetAllPortofolioItemsForOwner(Owner.Id);

            var ViewModel = new PortofolioViewModel
            {
                Owner           = Owner,
                portofolioItems = portofolioItems,
                AppTitle        = "My Portofolio"
            };

            return(View(ViewModel));
        }
Example #2
0
        public ActionResult AddPortofolio(PortofolioViewModel model)
        {
            List <Category> list = db.Categories.ToList();

            ViewBag.CategoryList = new SelectList(list, "Id_Category", "Category_Name");

            var file = model.ImageUpload;

            byte[] imagebyte = null;

            if (file != null)
            {
                string filename  = Path.GetFileNameWithoutExtension(file.FileName);
                string extension = Path.GetExtension(file.FileName);

                filename = filename + DateTime.Now.ToString("yymmssff") + extension;

                file.SaveAs(Server.MapPath("/Images/gallery/" + filename));
                BinaryReader reader = new BinaryReader(file.InputStream);
                imagebyte = reader.ReadBytes(file.ContentLength);
                Portofolio porto = new Portofolio();

                porto.Title      = model.Title;
                porto.Category   = model.Category;
                porto.ImageTitle = filename;
                porto.ImageByte  = imagebyte;
                porto.ImagePath  = "/Images/gallery/" + filename;

                db.Portofolios.Add(porto);
                db.SaveChanges();
            }
            var response = true;

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        public ActionResult Index(PortofolioViewModel model)
        {
            Category category = new Category();

            category.Category_Name = model.Category_Name;

            db.Categories.Add(category);
            db.SaveChanges();

            var response = true;

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Example #4
0
        public ActionResult UpdatePortofolio(PortofolioViewModel model)
        {
            if (model.Id_Portofolio > 0)
            {
                Portofolio porto = new Portofolio();

                porto = db.Portofolios.SingleOrDefault(x => x.Id_Portofolio == model.Id_Portofolio);

                porto.Title    = model.Title;
                porto.Category = model.Category;

                db.SaveChanges();
            }

            var response = true;

            return(Json(response, JsonRequestBehavior.AllowGet));
        }