public ActionResult GetListPortfolioByType(int idType)
 {
     if (!PUsing.GetPorfolioListFromItem(idType).Any()) return null;
     _portfolio = PUsing.GetPorfolioListFromItem(idType).First();
     EntityPortfolio entityPortfolio = new EntityPortfolio(PUsing.GetNextId(_portfolio.ID, idType),
         PUsing.GetPrevId(_portfolio.ID, idType), _portfolio);
     return PartialView("CaruselPortfolio", entityPortfolio);
 }
        public ActionResult GetItem(int idElement,int idType = 0)
        {
            _portfolio = db.PortfolioНабор.Find(idElement);
                EntityPortfolio entityPortfolio = new EntityPortfolio(PUsing.GetNextId(_portfolio.ID, idType),
                    PUsing.GetPrevId(_portfolio.ID, idType), _portfolio);

            return PartialView("CaruselPortfolio", entityPortfolio);
        }
 public EntityPortfolio(int next, int prev, Portfolio port)
 {
     this.Next = next;
     this.Prev = prev;
     this.ID = port.ID;
     this.ImgUrls = port.ImgUrls;
     this.Text = port.Text;
     this.Title = port.Title;
 }
        public JsonResult GetPorfolioElement(int idT, int id)
        {
            Portfolio returnPortfolio = new Portfolio();
            if (idT != 0)
            {
                var selectType = from itemType in db.TypePortfolioНабор
                                 where itemType.ID == idT
                                 select itemType;
                TypePortfolio typeObj = selectType.First();
                List<Portfolio> por = new List<Portfolio>();
                if (!typeObj.Stype)
                {
                    foreach (var porftolio in typeObj.TypePortfolio2.Select(element => (from item in db.PortfolioНабор
                                                                                        where item.TypePortfolio.ID == element.ID
                                                                                        select item)))
                    {
                        por.AddRange(porftolio.ToList());
                    }

                    var selection = from itemPortfolio in db.PortfolioНабор
                                    where (itemPortfolio.TypePortfolio.ID == idT) & (itemPortfolio.ID == id)
                                    select itemPortfolio;
                }
                else {
                    var select = from itemPortfolio in db.PortfolioНабор
                                 where itemPortfolio.TypePortfolio.ID == idT
                                 select itemPortfolio;
                    por.AddRange(select);
                }
                if (id == 0)
                {
                    returnPortfolio = por[0];
                }
                else {
                    var select = from item in por
                                 where item.ID == id
                                 select item;
                   returnPortfolio = select.First();
                    }
                }

            else {
                if (id == 0)
                {
                    returnPortfolio = db.PortfolioНабор.First();
                }
                else {
                    var select = from item in db.PortfolioНабор
                                 where item.ID == id
                                 select item;
                    returnPortfolio = select.First();
                }
            }

            return Json(returnPortfolio);
        }
 public int GetPrevId(int idElement, int idType)
 {
     if (GetPorfolioListFromItem(idType).Any(a => (a.ID > idElement) & a.Published))
     {
         _portfolio = GetPorfolioListFromItem(idType).Last(a => (a.ID > idElement) & a.Published);
     }
     else
     {
         _portfolio = GetPorfolioListFromItem(idType).Last(a => a.Published);
     }
     return _portfolio.ID;
 }
        public int GetNextId(int idElement, int idType)
        {
            // IEnumerable<Portfolio> portfolios = from a in GetPorfolioListFromItem(idType) where ((a.ID > idElement) & a.Published) select a;
            //_portfolio = portfolios.Any() ? portfolios.First() : db.PortfolioНабор.First(a => a.Published);
            if (GetPorfolioListFromItem(idType).Any(a => (a.ID > idElement) & a.Published))
            {
                _portfolio = GetPorfolioListFromItem(idType).First(a => (a.ID > idElement) & a.Published);
            }
            else
            {
                _portfolio = GetPorfolioListFromItem(idType).First(a => a.Published);
            }

            return _portfolio.ID;
        }
        public JsonResult EditPortfolio(Portfolio port, IEnumerable<ImgUrls> images, int typePortf, int stypePortf = 0)
        {
            port.TypePortfolio = db.TypePortfolioНабор.Find(stypePortf == 0 ? typePortf : stypePortf);
            foreach (var img in images)
            {
                if (img.Description == null)
                {
                    img.Description = "";
                }
                db.Entry(img).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    return Json("Ошибка");
                }
            }
            port.ImgUrls = (ICollection<ImgUrls>)images;
            db.Entry(port).State = EntityState.Modified;

            //db.Entry(port.ImgUrls).State = EntityState.Modified;
            try
            {
                db.SaveChanges();
                return new JsonResult();
            }
            catch
            {
                return new JsonResult();
            }
            //return new JsonResult();
        }
 public ActionResult EditPortfolio(int id = 0)
 {
     portfolio = db.PortfolioНабор.Find(id);
     #region вытаскиваем dropdownlist
     //ViewBag.typePortf = new SelectList(_portfUsing.GetLocalTypePortfolio(), "ID", "Name",portfolio.TypePortfolio.Name);
     List<TypePortfolio> list = new List<TypePortfolio>();
     ViewBag.stypePortf = new SelectList(list, "ID", "Name");
     if (portfolio.TypePortfolio.Stype)
     {
         foreach (var item in from item in db.TypePortfolioНабор where !item.Stype from sitem in item.TypePortfolio2 where sitem.ID == portfolio.TypePortfolio.ID select item)
         {
             _typePortf = item;
         }
         _stypePortf = portfolio.TypePortfolio;
     }
     else
     {
         _typePortf = portfolio.TypePortfolio;
     }
     // TypeDropDownList(_typePortf.ID);
     listPortfolio.AddRange(_typePortf.TypePortfolio2);
     ViewBag.typePortf = new SelectList(_portfUsing.GetLocalTypePortfolio(), "ID", "Name", _typePortf.ID);
     ViewBag.stypePortf = new SelectList(listPortfolio, "ID", "Name", _stypePortf.ID);
     Session["IDportfolio"] = portfolio.ID;
     #endregion
     if (portfolio == null)
     {
         return HttpNotFound();
     }
     return View(portfolio);
 }
 public String DeletePortfolioItem(int id)
 {
     portfolio = db.PortfolioНабор.Find(id);
     if (portfolio != null)
     {
         _imgList = portfolio.ImgUrls.ToList();
         //Удаляем все картинки, в последствии дописать удаление файлов
         foreach (var imgItem in _imgList)
         {
             db.ImgUrlsНабор.Remove(imgItem);
         }
         db.PortfolioНабор.Remove(portfolio);
         try
         {
             db.SaveChanges();
             return "Success";
         }
         catch
         {
             return "Error,problems whith db";
         }
     }
     return "Error, id not found";
 }
        public ActionResult Index()
        {
            entityMain.TypePortfolios = db.TypePortfolioНабор;
            if (!db.PortfolioНабор.Any())
            {
                return View("Error");
            }

            _portfolio = db.PortfolioНабор.First();
                int idType = db.TypePortfolioНабор.First().ID;
                entityMain.Portfolio = new EntityPortfolio(PUsing.GetNextId(_portfolio.ID, idType),
                    PUsing.GetPrevId(_portfolio.ID, idType), _portfolio);

            entityMain.Email = new EmailModel();
            return View(entityMain);
        }