// GET: Create
        public ActionResult Create(string title)
        {
            var model = new SampleModels();

            ViewBag.CollectionTitle = title;
            return(View(model));
        }
Example #2
0
        public void Add(SampleModel sampleModel)
        {
            var id = SampleModels.Max(s => s.Id);

            sampleModel.Id = ++id;
            SampleModels.Add(sampleModel);
        }
        public ActionResult Edit(SampleModels sampleModels, HttpPostedFileBase LargeImage)
        {
            if (ModelState.IsValid)
            {
                SampleModelMethods sampleModelMethods = new SampleModelMethods();

                if (LargeImage != null)
                {
                    //deleting old large image file.
                    var oldLargeImageUrlPath = Path.Combine(HttpContext.Server.MapPath(sampleModels.LargeImageUrl));

                    //saving small image and receiving back their urls.
                    sampleModels.LargeImageUrl = sampleModelMethods.SaveLargeImage(LargeImage);
                    if (System.IO.File.Exists(oldLargeImageUrlPath))
                    {
                        System.IO.File.Delete(oldLargeImageUrlPath);
                    }
                }



                db.Entry(sampleModels).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(sampleModels));
        }
        public ActionResult Create([Bind(Include = "ModelId,Name,IsEnabled")] SampleModels sampleModels, HttpPostedFileBase LargeImage)
        {
            if (ModelState.IsValid)
            {
                if (LargeImage != null)
                {
                    //saving both small and large images and receiving back their urls.
                    SampleModelMethods sampleModelMethods = new SampleModelMethods();
                    sampleModels.LargeImageUrl = sampleModelMethods.SaveLargeImage(LargeImage);

                    //adding records to database..
                    db.models.Add(sampleModels);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Please Select an image for project.");
                }
                //db.models.Add(sampleModels);
                //db.SaveChanges();
                //return RedirectToAction("Index");
            }

            return(View(sampleModels));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            SampleModels sampleModels = db.models.Find(id);

            db.models.Remove(sampleModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #6
0
 private ItemService() // 外部からのインスタンス生成を抑止
 {
     SampleModels.Add(new SampleModel
     {
         Id      = 0,
         Created = DateTime.Now,
         Text    = "Sample text."
     });
 }
Example #7
0
        public void Update(SampleModel sampleModel)
        {
            var target = SampleModels.FirstOrDefault(p => p.Id == sampleModel.Id);

            if (target == null)
            {
                throw new KeyNotFoundException($"Key: {sampleModel.Id}");
            }
            target.Created = sampleModel.Created;
            target.Text    = sampleModel.Text;
        }
        // GET: Admin/SampleModels/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SampleModels sampleModels = db.models.Find(id);

            if (sampleModels == null)
            {
                return(HttpNotFound());
            }
            return(View(sampleModels));
        }
        public ActionResult Edit(SampleModels sample, string title, int?page)
        {
            ViewBag.CollectionTitle = title;
            var oldSample = db.SampleModel.Where(m => m.Id == sample.Id).FirstOrDefault();

            db.SampleModel.Remove(oldSample);
            db.SaveChanges();

            var newSample = new SampleModels();

            newSample.Collection_Title = title;
            newSample.Donor_Count      = sample.Donor_Count;
            newSample.Material_Type    = sample.Material_Type;
            newSample.Last_Updated     = DateTime.Now.ToShortDateString();

            db.SampleModel.Add(newSample);
            db.SaveChanges();

            var sampleList = db.SampleModel.Where(m => m.Collection_Title == title).ToList().ToPagedList(page ?? 1, 6);

            return(View("Index", sampleList));
        }
        public ActionResult Create(SampleModels sample, string title, int?page)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            ViewBag.CollectionTitle = title;

            var getCollectionTitle = db.CollectionModel.Where(m => m.Title == sample.Collection_Title).FirstOrDefault();
            var newSample          = new SampleModels();

            newSample.Collection_Title = title;
            newSample.Donor_Count      = sample.Donor_Count;
            newSample.Material_Type    = sample.Material_Type;
            newSample.Last_Updated     = DateTime.Now.ToShortDateString();

            db.SampleModel.Add(newSample);
            db.SaveChanges();

            var sampleList = db.SampleModel.Where(m => m.Collection_Title == title).ToList().ToPagedList(page ?? 1, 6);

            return(View("Index", sampleList));
        }
 public IActionResult GetDefault() => Json(SampleModels.CreateSquad());