private static Document SetDocumentChangeFields(cis db, EasyDiaDocument item)
        {
            if (item.DocCardId > 0 && item.Active)
            {
                foreach (var document in db.Documents.Where(m => m.DocCardId == item.DocCardId))
                {
                    document.Active = false;
                }
            }
            var doc = db.Documents.Find(item.Id);

            doc.DocCardId = item.DocCardId;
            doc.DocTypeId = GetDocCardTypeId(db, doc);
            doc.Active    = item.Active;
            return(doc);
        }
        public IHttpActionResult SetDocument(int?userId, [FromBody] EasyDiaDocument body)
        {
            using (var db = new cis(User.Identity.Name, userId))
            {
                try
                {
                    var doc = SetDocumentChangeFields(db, body);

                    db.SaveChanges();

                    return(Json <object>(new { result = "Документы успешно связаны и будут загружены в ближайшее время" }));
                }
                catch (Exception ex)
                {
                    return(BadRequest(CISLibApp.Basic.Tools.BasicTools.GetErrorMessage(ex)));
                }
            }
        }