Exemplo n.º 1
0
        private tsilurik_documents _editDocument(List <Dictionary <string, object> > fields, out string msg)
        {
            var res = new tsilurik_documents();

            msg = "";
            try
            { var id   = RDL.Convert.StrToInt(AjaxModel.GetValueFromSaveField("id", fields), 0);
              var item = db.GetDocument(id);

              item.number       = AjaxModel.GetValueFromSaveField("number", fields);
              item.sum          = RDL.Convert.StrToDecimal(AjaxModel.GetValueFromSaveField("sum", fields), 0);
              item.contractorID = RDL.Convert.StrToInt(AjaxModel.GetValueFromSaveField("contractor", fields), 0);
              item.typeID       = RDL.Convert.StrToInt(AjaxModel.GetValueFromSaveField("type", fields), 0);
              item.note         = AjaxModel.GetValueFromSaveField("note", fields);
              item.link         = AjaxModel.GetValueFromSaveField("link", fields);
              db.SaveDocument(item);
              res = item; }
            catch (Exception ex)
            {
                _debug(ex, new { documentID = res.id });
                res = null;
                msg = "Сбой при выполнении операции";
            }

            return(res);
        }
Exemplo n.º 2
0
        private bool _canManageDocument(aspnet_Users user, tsilurik_documents item)
        {
            var res = false;

            if ((user != null && user.UserName == "*****@*****.**") && (item == null || item is tsilurik_documents))
            {
                return(true);
            }
            return(res);
        }
Exemplo n.º 3
0
        public tsilurik_documents CreateDocument(Dictionary <string, object> parameters, aspnet_Users user, out string msg)
        {
            var res = new tsilurik_documents();

            msg = "";
            try
            {
                if (!_canManageDocument(user, res))
                {
                    msg = "Нет прав для данной операции";
                    return(res = null);
                }
                var fields = (parameters["fields"] as ArrayList).ToArray().ToList().Select(x => x as Dictionary <string, object>).ToList();
                if (RDL.Convert.StrToInt(AjaxModel.GetValueFromSaveField("id", fields), 0) == 0)
                {
                    var date         = DateTime.Now;
                    var number       = AjaxModel.GetValueFromSaveField("number", fields);
                    var sum          = RDL.Convert.StrToDecimal(AjaxModel.GetValueFromSaveField("sum", fields), 0);
                    var contractorID = RDL.Convert.StrToInt(AjaxModel.GetValueFromSaveField("contractor", fields), 0);
                    var statusID     = GetDocumentStatuses().FirstOrDefault(x => x.name == "создан").id;
                    var typeID       = RDL.Convert.StrToInt(AjaxModel.GetValueFromSaveField("type", fields), 0);
                    var note         = AjaxModel.GetValueFromSaveField("note", fields);
                    var link         = AjaxModel.GetValueFromSaveField("link", fields);
                    var item         = new tsilurik_documents {
                        number = number, date = date, sum = sum, contractorID = contractorID, statusID = statusID,
                        typeID = typeID, note = note, link = link
                    };
                    db.SaveDocument(item);
                    res = item;
                }
                else
                {
                    res = _editDocument(fields, out msg);
                }
            }
            catch (Exception ex)
            {
                _debug(ex, new { userName = user.UserName });
                res = null;
                msg = "Сбой при выполнении операции";
            }

            return(res);
        }
Exemplo n.º 4
0
 public int SaveDocument(tsilurik_documents item, bool withSave = true)
 {
     if (item.id == 0)
     {
         Db.tsilurik_documents.Add(item);
         if (withSave)
         {
             Save();
         }
     }
     else
     {
         Db.Entry(item).State = EntityState.Modified;
         if (withSave)
         {
             Save();
         }
     }
     return(item.id);
 }
Exemplo n.º 5
0
        public bool _logDocumentStatuses(tsilurik_documents item, string note = "")
        {
            var res = false;

            try
            {
                db.SaveLogsDocumentStatus(new tsilurik_statusLog
                {
                    created    = DateTime.Now,
                    statusID   = item.statusID,
                    documentID = item.id,
                    note       = note
                });
                res = true;
            }
            catch (Exception ex)
            {
                _debug(ex, new { documentID = item.id, statusID = item.statusID, note });
            }
            return(res);
        }
Exemplo n.º 6
0
        public tsilurik_documents GetDocument(int id, aspnet_Users user, out string msg)
        {
            var res = new tsilurik_documents();

            msg = "";
            try
            {
                res = db.GetDocument(id);
                if (!_canAccessToDocument(user, res))
                {
                    msg = "Нет прав для данной операции";
                    return(res = null);
                }
            }
            catch (Exception ex)
            {
                _debug(ex, new { documentID = id, userName = user.UserName });
                res = null;
                msg = "Сбой при выполнении операции";
            }

            return(res);
        }