public HttpResponseMessage put(int id, DOCUMENTS documents) { try { using (DocumentsEntities entities = new DocumentsEntities()) { var entity = entities.DOCUMENTS.FirstOrDefault(e => e.DocumentId == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Documents doesnt exist")); } else { entity.DocumentId = documents.DocumentId; entity.EmployeeId = documents.EmployeeId; entity.DocumentTitle = documents.DocumentTitle; entity.DocumentPhoto = documents.DocumentPhoto; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public void AddMissingDocs(ISet <string> searchPropIds, string fileName) { if (searchPropIds != null) { IEnumerable <DocStatusView> status = this.GetDocsStatus().ToList().Where(doc => searchPropIds.Contains(doc.PropertyId.ToString())); DbSet <Document> docs = this.GetDocuments(); foreach (DocStatusView docStt in status) { foreach (DocTypeEnum type in Enum.GetValues(typeof(DocTypeEnum)).Cast <DocTypeEnum>()) { if (!IsExisting(type, docStt)) { var doc = docs.Add(new Document { Id = Guid.NewGuid(), PropertyId = docStt.PropertyId, DocType = type.ToString(), FileName = DocMgmtHelper.GetFilePathAndName(fileName)[1] }); string password = DocMgmtHelper.GetPassword(doc.Id.ToString(), doc.PropertyId.ToString()); doc.DocBlob = ZipHelper.ZipFileWithPassword(password, fileName); } } } dbContext.SaveChanges(); } }
public ActionResult Comment(Comment collection, int id) { var session = (THPDocument.Common.UserLogin)Session[THPDocument.Common.CommonConstants.USER_SESSION]; collection.ComentName = session.ID; db.Comments.Add(new Comment { ComentContent = collection.ComentContent, ComentName = collection.ComentName, DateComment = DateTime.Now, DocumentID = collection.DocumentID }); db.SaveChanges(); return(RedirectToAction("Details", "Home", new { id = id })); }
public ActionResult Index(Report collection) { var session = (THPDocument.Common.UserLogin)Session[THPDocument.Common.CommonConstants.USER_SESSION]; collection.ReportDate = DateTime.Now; collection.ReportBy = session.ID; db.Reports.Add(collection); db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here var model = db.Reports.Find(id); db.Reports.Remove(model); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public HttpResponseMessage post([FromBody] DOCUMENTS documents) { try { using (DocumentsEntities entities = new DocumentsEntities()) { entities.DOCUMENTS.Add(documents); entities.SaveChanges(); HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Created, documents); message.Headers.Location = new Uri(Request.RequestUri + documents.DocumentId.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult ChangePassword(int id, ChangePasswordModel model) { if (ModelState.IsValid) { var mk = db.Accounts.Find(id); if (mk.Password == model.OldPassword) { mk.Password = model.PasswordNew; db.SaveChanges(); ViewBag.Done = "Change password successfully!"; } else { ModelState.AddModelError("", "Old password is wrong!"); } return(View(model)); } return(View()); }
public HttpResponseMessage delete(int id) { try { using (DocumentsEntities entities = new DocumentsEntities()) { var entity = entities.DOCUMENTS.FirstOrDefault(e => e.DocumentId == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Documents doesnt exist")); } else { entities.DOCUMENTS.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }