public dynamic UploadFile() { HttpResponseMessage response = new HttpResponseMessage(); var httpRequest = HttpContext.Current.Request; int ProjectId = Convert.ToInt32(HttpContext.Current.Request.Form["ProjectId"]); if (httpRequest.Files.Count > 0) { var docfiles = new List <string>(); foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; string fileName = "Project_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg"; var filePath1 = HttpContext.Current.Server.MapPath("~/PropertyImages/" + fileName); Stream strm = postedFile.InputStream; Compressimage(strm, filePath1, postedFile.FileName); //_rent.SaveFile(new PropertyFileModel() { PropertyId = PropertyId, FileName = fileName }); RKBrickEntities _db = new RKBrickEntities(); ProjectFile projectFile = new ProjectFile(); projectFile.ProjectId = ProjectId; projectFile.ImgUrl = fileName; _db.ProjectFiles.Add(projectFile); _db.SaveChanges(); } response = Request.CreateResponse(HttpStatusCode.Created, docfiles); } else { response = Request.CreateResponse(HttpStatusCode.BadRequest); } return(response); }
public dynamic GetFiles(int ProjectId) { RKBrickEntities _db = new RKBrickEntities(); List <ProjectFile> files = _db.ProjectFiles.Where(x => x.ProjectId == ProjectId).ToList(); return(files); }
public ActionResult DeleteFiles(string fileId) { RKBrickEntities _db = new RKBrickEntities(); var pr = _db.ProjectFiles.FirstOrDefault(x => x.ImgUrl == fileId); _db.ProjectFiles.Remove(pr); _db.SaveChanges(); return(Json(true)); }
public ActionResult Delete(int ProjectId) { RKBrickEntities _db = new RKBrickEntities(); var pr = _db.Projects.FirstOrDefault(x => x.ProjectId == ProjectId); _db.Projects.Remove(pr); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult SaveProject(ProjectModel model) { RKBrickEntities _db = new RKBrickEntities(); Project pr = new Project(); pr.ProjectName = model.ProjectName; _db.Projects.Add(pr); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult _GalleryFiles() { RKBrickEntities _db = new RKBrickEntities(); List <ProjectFilesModel> data = (from m in _db.Projects join file in _db.ProjectFiles on m.ProjectId equals file.ProjectId select new ProjectModel() { ProjectName = m.ProjectName, ImgUrl = file.ImgUrl, ProjectId = m.ProjectId }).GroupBy(x => x.ProjectName, (key, g) => new ProjectFilesModel() { ProjectName = key, ImgUrl = g.FirstOrDefault().ImgUrl, ProjectId = g.FirstOrDefault().ProjectId }).ToList(); return(View(data)); }
// GET: Project public ActionResult Index() { RKBrickEntities _db = new RKBrickEntities(); return(View(_db.Projects.ToList())); }