示例#1
0
        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));
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        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 }));
        }
示例#4
0
        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"));
        }
示例#5
0
 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());
     }
 }
示例#6
0
 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));
     }
 }
示例#7
0
 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());
 }
示例#8
0
 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));
     }
 }