Example #1
0
 private static void AddObservationsToImgDao(IEnumerable <Observation> observations, ImageDAO imageDao, ICollection <ObservationDAO> observationDaos)
 {
     foreach (var obs in observations)
     {
         var observationDao = new ObservationDAO(imageDao, obs);
         imageDao.Add(observationDao);
         observationDaos.Add(observationDao);
     }
 }
Example #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")); }
        }
        private (ImageDAO, string) GenerateJsonsExamples()
        {
            var observations = new List <Observation>()
            {
                new Observation(_manager.GetOrCreate(0, "Car"), 0.5, new SKRect(0.1f, 0.2f, 0.7f, 0.8f)),
                new Observation(_manager.GetOrCreate(1, "Bat Mobile"), 0.7, new SKRect(0.1f, 0.2f, 0.7f, 0.8f)),
            };

            const string name         = "Image.jpg";
            var          creationTime = DateTime.UtcNow;
            var          testImg      =
                GraphicUtils.GetImageByDimensions(SharedConstants.DefaultChipWidth, SharedConstants.DefaultChipHeight);
            var imageDao = new ImageDAO(testImg, name, creationTime);

            foreach (var ob in observations)
            {
                imageDao.Add(new ObservationDAO(imageDao, ob));
            }

            return(imageDao, JSONService.ConvertToJson(imageDao));
        }
Example #4
0
 public ActionResult NewPhoto(int id, 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();
             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);
             return(RedirectToAction("EditApp", "Application", new { id = a.Id }));
         }
         return(RedirectToAction("Index", "Home"));
     }
     catch { return(RedirectToAction("Index", "Home")); }
 }
Example #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");
        }