public IHttpActionResult PutChecklistImage(int id, ChecklistImage checklistImage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != checklistImage.Id)
            {
                return(BadRequest());
            }

            db.Entry(checklistImage).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ChecklistImageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        private void SetCheckListImages_Upload(Checklist checklist, string ImageURL)
        {
            List <ChecklistImage> lstImages = new List <ChecklistImage>();

            //Local Images
            for (int i = 0; i < Request.Files.Count; i++)
            {
                Guid   guid     = Guid.NewGuid();
                string filename = Request.Files[i].FileName;
                if (filename == "")
                {
                    break;
                }
                string         type           = filename.Substring(filename.IndexOf("."), filename.Length - filename.IndexOf("."));
                string         mapPath        = "~/Content/UserFiles/Images/" + guid.ToString() + type;
                string         physicalPath   = Server.MapPath(mapPath);
                ChecklistImage checklistImage = new ChecklistImage();
                checklistImage.Path        = mapPath;
                checklistImage.Type        = 1;
                checklistImage.CheckListId = checklist.Id;
                lstImages.Add(checklistImage);
                Request.Files[i].SaveAs(physicalPath);
            }
            //URL Images
            if (ImageURL != null)
            {
                SaveImageURL(lstImages, ImageURL, checklist.Id);
            }
            checklist.CheckListImage = lstImages;
        }
예제 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            ChecklistImage checklistImage = GetChecklistMain(id);

            mAPICheckListImageController.DeleteChecklistImage(id);
            return(RedirectToAction("Index"));
        }
예제 #4
0
 public ActionResult Edit([Bind(Include = "Id,Path,CheckListId,Type")] ChecklistImage checklistImage)
 {
     if (ModelState.IsValid)
     {
         mAPICheckListImageController.PutChecklistImage(checklistImage.Id, checklistImage);
         return(RedirectToAction("Index"));
     }
     return(View(checklistImage));
 }
        public IHttpActionResult GetChecklistImage(int?id)
        {
            ChecklistImage checklistImage = db.CheckListImages.Find(id);

            if (checklistImage == null)
            {
                return(NotFound());
            }

            return(Ok(checklistImage));
        }
        public IHttpActionResult PostChecklistImage(ChecklistImage checklistImage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CheckListImages.Add(checklistImage);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = checklistImage.Id }, checklistImage));
        }
예제 #7
0
 public void SaveImageURL(List <ChecklistImage> lstImages, string imageURL, int checklistid)
 {
     using (WebClient client = new WebClient())
     {
         Guid   guid     = Guid.NewGuid();
         string filename = Server.MapPath("~/Content/UserFiles/Images/" + guid.ToString() + ".jpg");
         client.DownloadFile(new Uri(imageURL), filename);
         ChecklistImage checklistImage = new ChecklistImage();
         checklistImage.Path        = "~/Content/UserFiles/Images/" + guid.ToString() + ".jpg";
         checklistImage.Type        = 1;
         checklistImage.CheckListId = checklistid;
         lstImages.Add(checklistImage);
     }
 }
        public IHttpActionResult DeleteChecklistImage(int id)
        {
            ChecklistImage checklistImage = db.CheckListImages.Find(id);

            if (checklistImage == null)
            {
                return(NotFound());
            }

            db.CheckListImages.Remove(checklistImage);
            db.SaveChanges();

            return(Ok(checklistImage));
        }
예제 #9
0
        // GET: ChecklistImages/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChecklistImage checklistImage = GetChecklistMain(id);

            if (checklistImage == null)
            {
                return(HttpNotFound());
            }
            return(View(checklistImage));
        }
예제 #10
0
        public async Task <UserChecklist> AddUserChecklistImage(int checklistId, string ImageName)
        {
            var userChecklist = await _context.UserChecklists.FirstOrDefaultAsync(uc => uc.Id == checklistId);

            var checklistImage = new ChecklistImage(ImageName, $"https://checklist-image.s3.eu-central-1.amazonaws.com/" + ImageName);

            if (userChecklist.ChecklistImages == null)
            {
                userChecklist.ChecklistImages = new List <ChecklistImage>();
            }
            userChecklist.ChecklistImages.Add(checklistImage);
            _context.UserChecklists.Update(userChecklist);
            return(userChecklist);
        }