Esempio n. 1
0
        public HttpResponseMessage Get()
        {
            PicturesModel       model = new PicturesModel();
            HttpResponseMessage msg   = Request.CreateResponse <PicturesModel>(HttpStatusCode.OK, model);

            return(msg);
        }
        public ActionResult List(int?page)
        {
            try
            {
                int pageSize   = 20;
                int pageNumber = (page ?? 1);

                List <string> fileEntries = Directory.GetFiles(Server.MapPath("~/Images/Pictures")).ToList();

                PicturesModel pictures = new PicturesModel();

                var namesList = new List <string>();

                foreach (var item in fileEntries)
                {
                    FileInfo fi = new FileInfo(item);
                    namesList.Add(string.Format(@"../Images/Pictures/{0}", fi.Name));
                }
                int totalCount = namesList.Count;
                namesList = namesList.Skip((pageNumber - 1) * pageSize).Take(pageSize).OrderBy(q => q).ToList();

                var pagedList = new StaticPagedList <string>(namesList, pageNumber, pageSize, totalCount);
                pictures.Items = pagedList;

                return(View(pictures));
            }
            catch (Exception e)
            {
                log.Error(e);
                throw;
            }
        }
Esempio n. 3
0
        public ActionResult Create2(int eventId)
        {
            PicturesModel picturesModel = new PicturesModel();

            picturesModel.IdEvent  = eventId;
            picturesModel.Pictures = pFactory.getPictures(eventId);

            return(View(picturesModel));
        }
        public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, PicturesModel viewModel)
        {
            var error = this.LoadModel <PicturesModel, bool>(false).Destroy(viewModel, this.ModelState);

            if (error != null)
            {
                return(this.Json(error));
            }

            return(this.GridOperation(viewModel, request));
        }
        public ActionResult PictureUpload()
        {
            Organisation organisation = oFactory.oRepository.GetOrganisationByUsername(User.Identity.Name);

            PicturesModel picturesModel = new PicturesModel();

            picturesModel.IdOrganisation = organisation.Id;
            picturesModel.Pictures       = pFactory.getPicturesOrganisation(organisation.Id);

            return(View(picturesModel));
        }
        public ActionResult Destroy([DataSourceRequest]DataSourceRequest request, PicturesModel viewModel)
        {

            var error = this.LoadModel<PicturesModel, bool>(false).Destroy(viewModel, this.ModelState);

            if (error != null)
            {
                return this.Json(error);
            }

            return this.GridOperation(viewModel, request);
        }
        public ActionResult Save([DataSourceRequest] DataSourceRequest request, PicturesModel viewModel)
        {
            if (viewModel.HasImage)
            {
                viewModel.Files = (HttpPostedFileBase[])this.TempData["UploadedFile"];
                this.TempData["UploadedFile"] = null;
            }

            var error = this.LoadModel <PicturesModel, bool>(false).Save(viewModel, this.ModelState);

            if (error != null)
            {
                return(this.Json(error));
            }

            return(this.GridOperation(viewModel, request));
        }
        public ActionResult Save([DataSourceRequest]DataSourceRequest request, PicturesModel viewModel)
        {
            if (viewModel.HasImage)
            {
                viewModel.Files = (HttpPostedFileBase[])this.TempData["UploadedFile"];
                this.TempData["UploadedFile"] = null;
            }

            var error = this.LoadModel<PicturesModel, bool>(false).Save(viewModel, this.ModelState);

            if (error != null)
            {
                return this.Json(error);
            }

            return this.GridOperation(viewModel, request);
        }
 public HomeController()
 {
     if (picturesModel == null)
     {
         picturesModel = new PicturesModel();
     }
     if (homeModel == null)
     {
         homeModel = new HomePageModel(picturesModel.pictures.Count);
     }
     picturesModel.PictureDeleted += homeModel.UpdatePicCounter;
     if (logModel == null)
     {
         logModel = new LogPageModel();
     }
     if (configModel == null)
     {
         configModel = new ConfigModel();
     }
 }
        public ActionResult FileUpload(HttpPostedFileBase file, string caption, string type, string BadBees)
        {
            try
            {
                Item ifExist = db.Item.Where(q => (q.BadBee.BadBeeNo == BadBees)).FirstOrDefault();
                if (ifExist == null)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    PicturesModel pictures = new PicturesModel();

                    if (file != null)
                    {
                        if (!string.IsNullOrEmpty(BadBees))
                        {
                            caption = BadBees;
                        }

                        string pic  = "";
                        string path = "";

                        if (type == "schema1")
                        {
                            pic = Path.GetFileName(caption + "a.jpg");
                        }
                        else if (type == "schema2")
                        {
                            pic = Path.GetFileName(caption + "b.jpg");
                        }
                        else if (type == "picture2")
                        {
                            pic = Path.GetFileName(caption + "_2.jpg");
                        }
                        else if (type == "picture1")
                        {
                            pic = Path.GetFileName(caption + "_1.jpg");
                        }

                        if (BadBees == null)
                        {
                            BadBees = "";
                        }

                        Picture obj = db.Picture.Where(q => (q.BadBeeNo == BadBees)).FirstOrDefault();

                        if (obj != null)
                        {
                            List <Item> product = db.Item.Where(q => (q.BadBee.BadBeeNo == obj.BadBeeNo)).ToList();

                            if (type == "schema1" && obj.Picture1 != pic)
                            {
                                obj.Picture1 = pic;
                                using (var dbCtx = new BadBeeEntities())
                                {
                                    db.Picture.Attach(obj);
                                    db.Entry(obj).Property(x => x.Picture1).IsModified = true;
                                    dbCtx.SaveChanges();
                                }
                            }
                            if (type == "schema2" && obj.Picture2 != pic)
                            {
                                obj.Picture2 = pic;
                                using (var dbCtx = new BadBeeEntities())
                                {
                                    db.Picture.Attach(obj);
                                    db.Entry(obj).Property(x => x.Picture2).IsModified = true;
                                    dbCtx.SaveChanges();
                                }
                            }
                            if (type == "picture2" && obj.Picture3 != pic)
                            {
                                obj.Picture3 = pic;
                                using (var dbCtx = new BadBeeEntities())
                                {
                                    db.Picture.Attach(obj);
                                    db.Entry(obj).Property(x => x.Picture3).IsModified = true;
                                    dbCtx.SaveChanges();
                                }
                            }

                            Picture newPict = new Picture();
                            newPict = db.Picture.Where(q => q.PictureId == obj.PictureId).FirstOrDefault();
                        }
                        else
                        {
                            Picture newObj = new Picture();
                            //var np = db.Pictures.OrderByDescending(q => q.Id).Select(q => q).FirstOrDefault();
                            //int newid = np.Id + 1;

                            //newObj.BadBeeNo = BadBees;
                            //if (type == "schema1") { newObj.Schema1 = pic; };
                            //if (type == "schema2") { newObj.Schema2 = pic; };

                            //if (type == "picture1") { newObj.Picture1 = pic; };
                            //if (type == "picture2") { newObj.Picture2 = pic; };
                            //newObj.Id = newid;

                            //List<ItemsDb> product = db.ItemsDb.Where(q => (q.BadBeeNumber == newObj.BadBeeNo)).ToList();
                            //foreach (var item in product)
                            //{
                            //    item.PictureId = newObj.Id;
                            //}

                            using (var dbCtx = new BadBeeEntities())
                            {
                                dbCtx.Picture.Add(newObj);
                                dbCtx.SaveChanges();
                            }
                        }

                        path = Path.Combine(Server.MapPath("~/Images/Pictures"), pic);

                        // file is uploaded

                        file.SaveAs(path);

                        using (MemoryStream ms = new MemoryStream())
                        {
                            file.InputStream.CopyTo(ms);
                            byte[] array = ms.GetBuffer();
                        }

                        db.SaveChanges();
                    }
                    //}
                    // after successfully uploading redirect the user
                    return(RedirectToAction("List", pictures));
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
        }