Пример #1
0
        public ActionResult ApproveApp(int id)
        {
            try
            {
                if (Session["ModId"] != null)
                {
                    UserDAO             udao  = new UserDAO();
                    User                u     = udao.SearchById(int.Parse(Session["Id"].ToString()));
                    ImageDAO            idao  = new ImageDAO();
                    ApplicationDAO      dao   = new ApplicationDAO();
                    TypeAppDAO          tdao  = new TypeAppDAO();
                    GenreDAO            gdao  = new GenreDAO();
                    PegiDAO             pdao  = new PegiDAO();
                    ApplicationGenreDAO agdao = new ApplicationGenreDAO();

                    ViewBag.Types   = tdao.List();
                    ViewBag.Pegis   = pdao.List();
                    ViewBag.AppGens = agdao.ListByApplication(id);
                    ViewBag.Genres  = gdao.List();
                    ViewBag.User    = u;
                    ViewBag.App     = dao.SearchById(id);
                    ViewBag.Img     = idao.SearchAppImages(id);
                    return(View());
                }
                return(RedirectToAction("Index", "Home"));
            }
            catch { return(RedirectToAction("Index", "Home")); }
        }
Пример #2
0
 public ActionResult SearchByGenre(int id)
 {
     try
     {
         ApplicationDAO           dao   = new ApplicationDAO();
         ApplicationGenreDAO      agdao = new ApplicationGenreDAO();
         IList <ApplicationGenre> agens = agdao.ListByGenre(id);
         IList <Application>      apps  = new List <Application>();
         CartDAO cdao = new CartDAO();
         if (Session["Id"] != null)
         {
             ViewBag.Cart = cdao.SearchCartUser(int.Parse(Session["Id"].ToString()));
         }
         foreach (var ag in agens)
         {
             apps.Add(dao.SearchById(ag.ApplicationId));
         }
         ViewBag.Apps = apps;
         return(View("Search"));
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Пример #3
0
 public ActionResult EditApp(int id)
 {
     try
     {
         ApplicationDAO      dao   = new ApplicationDAO();
         Application         App   = dao.SearchById(id);
         UserDAO             udao  = new UserDAO();
         TypeAppDAO          tdao  = new TypeAppDAO();
         PegiDAO             pdao  = new PegiDAO();
         GenreDAO            gdao  = new GenreDAO();
         ApplicationGenreDAO agdao = new ApplicationGenreDAO();
         if (Session["ModId"] != null || App.DeveloperId == int.Parse(Session["DevId"].ToString()))
         {
             ViewBag.User = udao.SearchById(int.Parse(Session["Id"].ToString()));
             ImageDAO idao = new ImageDAO();
             ViewBag.Imgs  = idao.SearchAppImages(App.Id);
             ViewBag.App   = App;
             ViewBag.Types = tdao.List();
             ViewBag.Pegis = pdao.List();
             IList <Genre>            genres = gdao.ListId();
             IList <ApplicationGenre> agens  = agdao.ListByApplication(id);
             foreach (var ag in agens)
             {
                 foreach (var g in genres)
                 {
                     if (ag.GenreId == g.Id)
                     {
                         g.IsChecked = true;
                     }
                 }
             }
             ViewBag.Genres = genres;
             return(View());
         }
         return(RedirectToAction("Index", "Home"));
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Пример #4
0
 public ActionResult UpdateGenres(IList <Genre> genres, int appId)
 {
     try
     {
         ApplicationDAO dao = new ApplicationDAO();
         Application    app = dao.SearchById(appId);
         if (Session["ModId"] != null || app.DeveloperId == int.Parse(Session["DevId"].ToString()))
         {
             ApplicationGenreDAO      agdao = new ApplicationGenreDAO();
             IList <ApplicationGenre> ags   = agdao.ListByApplication(appId);
             foreach (var g in genres)
             {
                 foreach (var ag in ags)
                 {
                     if (ag.GenreId == g.Id)
                     {
                         if (!g.IsChecked)
                         {
                             agdao.Remove(ag);
                         }
                     }
                 }
                 if (g.IsChecked == true)
                 {
                     ApplicationGenre ag = new ApplicationGenre();
                     ag.ApplicationId = appId;
                     ag.GenreId       = g.Id;
                     agdao.Add(ag);
                 }
             }
             return(RedirectToAction("EditApp", "Application", new { id = appId }));
         }
         return(RedirectToAction("Index", "Home"));
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Пример #5
0
        public ActionResult Validate(Application app, IList <HttpPostedFileBase> images, HttpPostedFileBase File, IList <Genre> genres)
        {
            var result = "";

            if (ModelState.IsValid)
            {
                try
                {
                    app.Approved = 0;
                    ApplicationDAO      dao = new ApplicationDAO();
                    Application         uniq = dao.IsUnique(app);
                    DeveloperDAO        ddao = new DeveloperDAO();
                    ImageDAO            idao = new ImageDAO();
                    ApplicationGenreDAO agdao = new ApplicationGenreDAO();
                    Developer           Dev = ddao.SearchById(int.Parse(Session["DevId"].ToString()));
                    bool ImgError = false, FileError = false, AGError = false;
                    if (Dev != null)
                    {
                        if (app.ReleaseDate.Year >= 1900 && app.ReleaseDate.Year <= DateTime.Now.Year + 1)
                        {
                            if (app.Price >= 0 && app.Price <= 1000)
                            {
                                if (uniq == null)
                                {
                                    app.DeveloperId = Dev.Id;
                                    dao             = new ApplicationDAO();
                                    dao.Add(app);
                                    Dev.NumSoft++;
                                    ddao.Update();

                                    Application appreg = dao.GetDevLastGame(Dev.Id);
                                    try
                                    {
                                        foreach (var g in genres)
                                        {
                                            if (g.IsChecked == true)
                                            {
                                                ApplicationGenre ag = new ApplicationGenre();
                                                ag.ApplicationId = appreg.Id;
                                                ag.GenreId       = g.Id;
                                                agdao.Add(ag);
                                            }
                                        }
                                    }
                                    catch
                                    {
                                        AGError = true;
                                    }

                                    try
                                    {
                                        //Images
                                        int count = 0;
                                        foreach (var img in images)
                                        {
                                            string filePath = Guid.NewGuid() + Path.GetExtension(img.FileName);
                                            img.SaveAs(Path.Combine(Server.MapPath("~/media/app"), filePath));
                                            Image i = new Image();
                                            i.Url           = "../../../media/app/" + filePath;
                                            i.UserId        = int.Parse(Session["Id"].ToString());
                                            i.ApplicationId = appreg.Id;
                                            idao.Add(i);
                                            if (count == 0)
                                            {
                                                appreg.ImageUrl = i.Url;
                                                count++;
                                                dao.Update();
                                            }
                                        }
                                        //
                                    }
                                    catch
                                    {
                                        appreg.ImageUrl = "../../../assets/images/game-kingdoms-of-amalur-reckoning-4-500x375.jpg";
                                        dao.Update();
                                        ImgError = true;
                                        result   = result + "Error on Uploading Images, try later";
                                    }
                                    try
                                    {
                                        //File
                                        string filePath2 = Guid.NewGuid() + Path.GetExtension(File.FileName);
                                        if (!Directory.Exists(Server.MapPath("~/apps/appfiles/" + appreg.Id)))
                                        {
                                            Directory.CreateDirectory(Server.MapPath("~/apps/appfiles/" + appreg.Id));
                                        }
                                        File.SaveAs(Path.Combine(Server.MapPath("~/apps/appfiles/" + appreg.Id), filePath2));
                                        appreg.Archive = "../../../apps/appfiles/" + appreg.Id + "/" + filePath2;
                                        dao.Update();
                                        //
                                    }
                                    catch
                                    {
                                        FileError = true;
                                        result    = result + "Error on Uploading Files, try later";
                                    }

                                    if (ImgError || FileError || AGError)
                                    {
                                        return(Json(result, JsonRequestBehavior.AllowGet));
                                    }


                                    result = "Successfully Registered";
                                    return(Json(result, JsonRequestBehavior.AllowGet));
                                    //return RedirectToAction("Register");
                                }
                                else
                                {
                                    result = "There is already a game with this name"; return(Json(result, JsonRequestBehavior.AllowGet));
                                }
                            }
                            else
                            {
                                result = "Application Price is not acceptable"; return(Json(result, JsonRequestBehavior.AllowGet));
                            }
                        }
                        else
                        {
                            result = "The release date is not acceptable"; return(Json(result, JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        result = "You are not a Developer"; return(Json(result, JsonRequestBehavior.AllowGet));
                    }
                }
                catch
                {
                    ViewBag.App = app;
                    result      = "An Error Occurred";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                    //return RedirectToAction("Register");
                }
            }
            ViewBag.App   = app;
            ViewBag.Class = "alert alert-danger";
            result        = "An Error Occurred";
            return(Json(result, JsonRequestBehavior.AllowGet));
            //return View("Register");
        }