Exemple #1
0
 public ActionResult Register(Review review)
 {
     try
     {
         ReviewDAO dao  = new ReviewDAO();
         UserDAO   udao = new UserDAO();
         review.Date = DateTime.Now;
         User u = udao.SearchById(int.Parse(Session["Id"].ToString()));
         review.UserId = u.Id;
         Review rev = dao.SearchByUserApp(review.UserId, review.ApplicationId);
         if (rev != null)
         {
             dao.Remove(rev);
         }
         dao.Add(review);
         IList <Review> revs      = dao.SearchByAppId(review.ApplicationId);
         double         totalrate = 0;
         foreach (var r in revs)
         {
             totalrate += r.Value;
         }
         totalrate = Math.Round(totalrate / revs.Count);
         ApplicationDAO appdao = new ApplicationDAO();
         Application    a      = appdao.SearchById(review.ApplicationId);
         a.Value = int.Parse(totalrate.ToString());
         appdao.Update();
         return(RedirectToAction("Product", "Application", new { id = review.ApplicationId }));
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemple #2
0
        public ActionResult EditPhoto(int id, int PhotoId, HttpPostedFileBase img)
        {
            try
            {
                ApplicationDAO dao = new ApplicationDAO();
                Application    a   = dao.SearchById(id);
                if (Session["ModId"] != null || int.Parse(Session["DevId"].ToString()) == a.DeveloperId)
                {
                    ImageDAO idao = new ImageDAO();

                    Image i = idao.SearchById(PhotoId);
                    bool  b = false;
                    if (a.ImageUrl == i.Url)
                    {
                        b = true;
                    }
                    //Delete Photo in Server
                    string p = i.Url;
                    p = p.Replace("../../..", "..");
                    string fullPath = Request.MapPath(p);
                    idao.Remove(i);
                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }
                    //Upload
                    string filePath = Guid.NewGuid() + Path.GetExtension(img.FileName);
                    img.SaveAs(Path.Combine(Server.MapPath("~/media/app"), filePath));
                    Image im = new Image();
                    im.Url           = "../../../media/app/" + filePath;
                    im.UserId        = int.Parse(Session["Id"].ToString());
                    im.ApplicationId = a.Id;
                    idao.Add(im);

                    if (b)
                    {
                        a.ImageUrl = im.Url;
                        dao.Update();
                    }

                    return(RedirectToAction("EditApp", "Application", new { id = a.Id }));
                }
                return(RedirectToAction("Index", "Home"));
            }
            catch { return(RedirectToAction("Index", "Home")); }
        }
Exemple #3
0
 public ActionResult TurntoMain(int id, int AppId)
 {
     try
     {
         ApplicationDAO dao = new ApplicationDAO();
         Application    a   = dao.SearchById(AppId);
         if (Session["ModId"] != null || int.Parse(Session["DevId"].ToString()) == a.DeveloperId)
         {
             ImageDAO idao = new ImageDAO();
             Image    i    = idao.SearchById(id);
             a.ImageUrl = i.Url;
             dao.Update();
             return(RedirectToAction("EditApp", "Application", new { id = a.Id }));
         }
         return(RedirectToAction("Index", "Home"));
     }
     catch { return(RedirectToAction("Index", "Home")); }
 }
Exemple #4
0
 public ActionResult Approve(int id)
 {
     try
     {
         if (Session["ModId"] != null)
         {
             ApplicationDAO dao = new ApplicationDAO();
             Application    a   = dao.SearchById(id);
             a.Approved = 1;
             dao.Update();
             return(RedirectToAction("ProfileView", "Moderator"));
         }
         else
         {
             return(RedirectToAction("Index", "Home"));
         }
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemple #5
0
        public ActionResult UpdateAppData(UpdateNotes update, HttpPostedFileBase file)
        {
            try
            {
                ApplicationDAO dao   = new ApplicationDAO();
                UpdateNotesDAO updao = new UpdateNotesDAO();
                Application    app   = dao.SearchById(update.ApplicationId);
                if (int.Parse(Session["DevId"].ToString()) == app.DeveloperId && update.Value != null)
                {
                    updao.Add(update);

                    //Delete File in Server
                    string p = app.Archive;
                    p = p.Replace("../../..", "..");
                    string fullPath = Request.MapPath(p);
                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }

                    //File
                    string filePath2 = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    if (!Directory.Exists(Server.MapPath("~/apps/appfiles/" + app.Id)))
                    {
                        Directory.CreateDirectory(Server.MapPath("~/apps/appfiles/" + app.Id));
                    }
                    file.SaveAs(Path.Combine(Server.MapPath("~/apps/appfiles/" + app.Id), filePath2));
                    app.Archive = "../../../apps/appfiles/" + app.Id + "/" + filePath2;
                    dao.Update();
                    //
                    return(RedirectToAction("Summary", "Developer"));
                }
                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemple #6
0
 public ActionResult UpdateInfo(Application app)
 {
     try
     {
         if (Session["ModId"] != null || app.DeveloperId == int.Parse(Session["DevId"].ToString()))
         {
             ApplicationDAO dao = new ApplicationDAO();
             Application    a   = dao.SearchById(app.Id);
             a.Name      = app.Name;
             a.Desc      = app.Desc;
             a.Price     = app.Price;
             a.TypeAppId = app.TypeAppId;
             a.PegiId    = app.PegiId;
             dao.Update();
             return(RedirectToAction("EditApp", "Application", new { id = app.Id }));
         }
         return(RedirectToAction("Index", "Home"));
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemple #7
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");
        }