public ActionResult ChangeStateWork([Bind(Include = "WorkListId,DateIn,DateOut,DateModifcation,Deadline,QueryId,WorkTypeId,PersonExecId,StateWorkId,Verification,Comment")] jWorkList jWorkList)
        {
            if (ModelState.IsValid)
            {
                db.Entry(jWorkList).State = EntityState.Modified;
                if (jWorkList.StateWorkId == db.hStateWork.First(m => m.Description == "Выполнена").StateWorkId || jWorkList.StateWorkId == db.hStateWork.First(m => m.Description == "Отклонена").StateWorkId)
                {
                    jWorkList.DateOut = DateTime.Parse(DateTime.Today.ToShortDateString());
                }
                if (Convert.ToInt32(TempData["oldState"]) != jWorkList.StateWorkId)
                {
                    jJournal jJur = new jJournal();
                    jJur.Date        = DateTime.Now;
                    jJur.EventTypeId = db.hEventType.First(m => m.Description == "Смена статуса работы").EventTypeId;
                    jJur.WorkListId  = jWorkList.WorkListId;
                    jJur.PersonId    = User.Identity.GetUserId();
                    jJur.QueryID     = jWorkList.QueryId;
                    hStateWork oldst = db.hStateWork.Find(Convert.ToInt32(TempData["oldState"]));
                    hStateWork newst = db.hStateWork.Find(jWorkList.StateWorkId);
                    jJur.Description = "c " + oldst.Description + " на " + newst.Description;
                    CloseQuery(jWorkList.QueryId);
                    db.jJournal.Add(jJur);
                }
                db.SaveChanges();


                return(RedirectToAction("Index"));
            }
            ViewBag.PersonExecId = new SelectList(db.AspNetUsers, "Id", "Fio", jWorkList.PersonExecId);
            ViewBag.StateWorkId  = new SelectList(db.hStateWork, "StateWorkId", "Description", jWorkList.StateWorkId);
            ViewBag.WorkTypeId   = new SelectList(db.hWorkType, "WorkTypeId", "Description", jWorkList.WorkTypeId);
            ViewBag.QueryId      = new SelectList(db.jQuery, "QueryId", "Text", jWorkList.QueryId);
            return(View(jWorkList));
        }
 public ActionResult ChangeWorker([Bind(Include = "WorkListId,DateIn,DateOut,DateModifcation,Deadline,QueryId,WorkTypeId,PersonExecId,StateWorkId,Verification,Comment")] jWorkList jWorkList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(jWorkList).State = EntityState.Modified;
         if (TempData["oldWork"].ToString() != jWorkList.PersonExecId)
         {
             jJournal jJur = new jJournal();
             jJur.Date        = DateTime.Now;
             jJur.EventTypeId = db.hEventType.First(m => m.Description == "Смена исполнителя").EventTypeId;
             jJur.WorkListId  = jWorkList.WorkListId;
             jJur.PersonId    = User.Identity.GetUserId();
             jJur.QueryID     = jWorkList.QueryId;
             AspNetUsers oldst = db.AspNetUsers.Find(TempData["oldWork"]);
             AspNetUsers newst = db.AspNetUsers.Find(jWorkList.PersonExecId);
             jJur.Description = "c " + oldst.Fio + " на " + newst.Fio;
             db.jJournal.Add(jJur);
         }
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PersonExecId = new SelectList(db.AspNetUsers, "Id", "Fio", jWorkList.PersonExecId);
     ViewBag.StateWorkId  = new SelectList(db.hStateWork, "StateWorkId", "Description", jWorkList.StateWorkId);
     ViewBag.WorkTypeId   = new SelectList(db.hWorkType, "WorkTypeId", "Description", jWorkList.WorkTypeId);
     ViewBag.QueryId      = new SelectList(db.jQuery, "QueryId", "Text", jWorkList.QueryId);
     return(View(jWorkList));
 }
        public ActionResult DeleteConfirmed(int id)
        {
            jWorkList jWorkList = db.jWorkList.Find(id);

            db.jWorkList.Remove(jWorkList);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: jWorkLists/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            jWorkList jWorkList = db.jWorkList.Find(id);

            if (jWorkList == null)
            {
                return(HttpNotFound());
            }
            return(View(jWorkList));
        }
 public ActionResult Edit([Bind(Include = "WorkListId,DateIn,DateOut,DateModifcation,Deadline,QueryId,WorkTypeId,PersonExecId,StateWorkId,Verification,Comment")] jWorkList jWorkList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(jWorkList).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PersonExecId = new SelectList(db.AspNetUsers, "Id", "Fio", jWorkList.PersonExecId);
     ViewBag.StateWorkId  = new SelectList(db.hStateWork, "StateWorkId", "Description", jWorkList.StateWorkId);
     ViewBag.WorkTypeId   = new SelectList(db.hWorkType, "WorkTypeId", "Description", jWorkList.WorkTypeId);
     ViewBag.QueryId      = new SelectList(db.jQuery, "QueryId", "Text", jWorkList.QueryId);
     return(View(jWorkList));
 }
        public ActionResult Create([Bind(Include = "WorkListId,DateIn,DateOut,DateModifcation,Deadline,QueryId,WorkTypeId,PersonExecId,StateWorkId,Verification,Comment")] jWorkList jWorkList)
        {
            if (ModelState.IsValid)
            {
                jWorkList.DateIn          = DateTime.Parse(DateTime.Today.ToShortDateString());
                jWorkList.DateModifcation = DateTime.Now;
                jWorkList.DateModifcation = jWorkList.DateModifcation.AddMilliseconds(-jWorkList.DateModifcation.Millisecond);
                DateTime dmd = jWorkList.DateModifcation;
                jWorkList.StateWorkId  = db.hStateWork.First(m => m.Description == "Ожидает").StateWorkId;
                jWorkList.Verification = false;
                if (jWorkList.Comment != null)
                {
                    string com = "-" + jWorkList.Comment + " " + User.Identity.Name + " " + DateTime.Now.ToString();
                    jWorkList.Comment = com;
                }
                db.jWorkList.Add(jWorkList);
                db.SaveChanges();

                jJournal jJur   = new jJournal();
                string   dmdstr = dmd.ToString("yyyy-MM-dd HH:mm:ss") + ".000";
                DateTime dmdn   = DateTime.Parse(dmdstr);
                db = new KOMK_Main_v2Entities();
                jWorkList jW = db.jWorkList.First(m => m.DateModifcation == dmdn);

                jJur.Date        = DateTime.Now;
                jJur.EventTypeId = db.hEventType.First(m => m.Description == "Создание работы").EventTypeId;
                jJur.WorkListId  = jW.WorkListId;
                jJur.PersonId    = User.Identity.GetUserId();
                jJur.QueryID     = jW.QueryId;
                if (jW.Comment != null)
                {
                    jJur.Description = " Коментарий перед работой: " + jW.Comment;
                }
                else
                {
                    jJur.Description = "Комментария перед работой не было";
                }

                db.jJournal.Add(jJur);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.PersonExecId = new SelectList(db.AspNetUsers, "Id", "Fio", jWorkList.PersonExecId);
            ViewBag.StateWorkId  = new SelectList(db.hStateWork, "StateWorkId", "Description", jWorkList.StateWorkId);
            ViewBag.WorkTypeId   = new SelectList(db.hWorkType, "WorkTypeId", "Description", jWorkList.WorkTypeId);
            ViewBag.QueryId      = new SelectList(db.jQuery, "QueryId", "Text", jWorkList.QueryId);
            return(View(jWorkList));
        }
        // GET: jWorkLists/ChangeStateWork/5
        public ActionResult Comments(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            jWorkList jWorkList = db.jWorkList.Find(id);

            if (jWorkList == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PersonExecId = new SelectList(db.AspNetUsers, "Id", "Fio", jWorkList.PersonExecId);
            ViewBag.StateWorkId  = new SelectList(db.hStateWork, "StateWorkId", "Description", jWorkList.StateWorkId);
            ViewBag.WorkTypeId   = new SelectList(db.hWorkType, "WorkTypeId", "Description", jWorkList.WorkTypeId);
            ViewBag.QueryId      = new SelectList(db.jQuery, "QueryId", "Text", jWorkList.QueryId);
            return(View(jWorkList));
        }
        // GET: jWorkLists/ChangeWorker/5
        public ActionResult ChangeWorker(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            jWorkList jWorkList = db.jWorkList.Find(id);

            TempData["oldWork"] = jWorkList.PersonExecId;
            if (jWorkList == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PersonExecId = new SelectList(GetListWromWT(db.hWorkType.Find(jWorkList.WorkTypeId).WorkTypeId), "Id", "Fio", jWorkList.PersonExecId);
            ViewBag.StateWorkId  = new SelectList(db.hStateWork, "StateWorkId", "Description", jWorkList.StateWorkId);
            ViewBag.WorkTypeId   = new SelectList(db.hWorkType, "WorkTypeId", "Description", jWorkList.WorkTypeId);
            ViewBag.QueryId      = new SelectList(db.jQuery, "QueryId", "Text", jWorkList.QueryId);
            return(View(jWorkList));
        }
 public ActionResult Comments([Bind(Include = "WorkListId,DateIn,DateOut,DateModifcation,Deadline,QueryId,WorkTypeId,PersonExecId,StateWorkId,Verification,Comment")] jWorkList jWorkList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(jWorkList).State = EntityState.Modified;
         if (Request.Form["addCom"] != "")
         {
             string com = "  -" + Request.Form["addCom"] + " " + User.Identity.Name + " " + DateTime.Now.ToString();
             jWorkList.Comment = jWorkList.Comment + "\n" + com;
         }
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PersonExecId = new SelectList(db.AspNetUsers, "Id", "Fio", jWorkList.PersonExecId);
     ViewBag.StateWorkId  = new SelectList(db.hStateWork, "StateWorkId", "Description", jWorkList.StateWorkId);
     ViewBag.WorkTypeId   = new SelectList(db.hWorkType, "WorkTypeId", "Description", jWorkList.WorkTypeId);
     ViewBag.QueryId      = new SelectList(db.jQuery, "QueryId", "Text", jWorkList.QueryId);
     return(View(jWorkList));
 }