Example #1
0
        public static List <string> getPermissions(string id, string tipo)
        {
            MongoModel userTable    = new MongoModel("Users");    //user's model
            MongoModel profileTable = new MongoModel("Profiles"); // profile's model
            String     usuarioid    = id;

            String  profileid     = userTable.GetRow(usuarioid);
            JObject rowArray      = JsonConvert.DeserializeObject <JObject>(profileid);
            string  idpro         = rowArray["profileId"].ToString();
            String  profiles      = profileTable.GetRow(idpro);
            JObject rowArraypro   = JsonConvert.DeserializeObject <JObject>(profiles);
            string  arraypermisos = rowArraypro["permissionsHTK"].ToString();
            JObject allp          = JsonConvert.DeserializeObject <JObject>(arraypermisos);
            var     permisos      = allp[tipo];
            string  datajson      = JsonConvert.SerializeObject(permisos);

            JObject allp2          = JsonConvert.DeserializeObject <JObject>(datajson);
            var     arraypermisos2 = allp2["grant"].ToArray();

            List <string> access = new List <string>();

            for (int i = 0; i < arraypermisos2.Length; i++)
            {
                access.Add(arraypermisos2[i].ToString());
            }

            return(access);
        }
Example #2
0
 /// <summary>
 ///     Initializes the models
 /// </summary>
 public AdjudicatingController()
 {
     listsModel        = new MongoModel("Lists");
     usersModel        = new MongoModel("Users");
     adjudicatingModel = new MongoModel("Adjudicating");
     _logTable         = new LogBook.Controllers.LogBookController();
 }
        /// <summary>
        ///     Allows to get the adjudicating index view
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            { //creating asssetsTypeOptions
              // String assetsTypeString = listsModel.Get("name", "_HTKassetsType");
              // JObject assetsType = JsonConvert.DeserializeObject<JArray>(assetsTypeString).First() as JObject;

                MongoModel Categories        = new MongoModel("Categories");
                String     assetsTypeOptions = "<option disabled>---------------------------</option>";

                try
                {
                    JArray catja = JsonConvert.DeserializeObject <JArray>(Categories.GetRows());
                    foreach (JObject cat in catja)
                    {
                        try
                        {
                            assetsTypeOptions += "<option value='" + cat["_id"].ToString() + "' >" + cat["name"].ToString() + "</option>";
                        }
                        catch { }
                    }
                }
                catch { }

                /* foreach (JObject item in (JArray)assetsType["elements"]["order"])
                 * {
                 *   foreach (KeyValuePair<String, JToken> element in item)
                 *   {
                 *       assetsTypeOptions += "<option value='" + element.Key + "'>" + element.Value + "</option>";
                 *   }
                 * }
                 *
                 * assetsTypeOptions += "<option disabled>---------------------------</option>";
                 *
                 * foreach (JObject item in (JArray)assetsType["elements"]["unorder"])
                 * {
                 *   foreach (KeyValuePair<String, JToken> element in item)
                 *   {
                 *       assetsTypeOptions += "<option value='" + element.Key + "'>" + element.Value + "</option>";
                 *   }
                 * }*/
                ViewData["assetsTypeOptions"] = new HtmlString(assetsTypeOptions);
            }

            { //creating usersOptions
                String usersOptions = "";
                String usersString  = usersModel.GetRows();
                JArray usersArray   = JsonConvert.DeserializeObject <JArray>(usersString);
                foreach (JObject user in usersArray)
                {
                    usersOptions += "<option value='" + user["_id"].ToString() + "'>" + user["user"].ToString() + "</option>";
                }
                ViewData["usersOptions"] = new HtmlString(usersOptions);
            }
            return(View());
        }
Example #4
0
 /// <summary>
 ///     Initializes the models and the agent
 /// </summary>
 public TicketsController()
 {
     Ticketsdb           = new MongoModel("Tickets");
     UsersTicketsdb      = new MongoModel("UsersTickets");
     Usersdb             = new MongoModel("Users");
     TicketChatdb        = new MongoModel("ChatTickets");
     agent               = null;
     messenger           = new Messenger();
     validatelim         = new ValidateLimits();
     validatepermissions = new validatePermissions();
 }
Example #5
0
        public List <string> sublocations(string idlocation, string profile)
        {
            List <string> ids = new List <string>();

            try
            {
                ObjectsRealReport custom     = new ObjectsRealReport("ObjectReal");
                MongoModel        locationdb = new MongoModel("Locations");

                if (profile == "Region")
                {
                    try
                    {
                        JArray conjuntos = JsonConvert.DeserializeObject <JArray>(locationdb.Get("parent", idlocation));
                        ids = (from conj in conjuntos select(string) conj["_id"]).ToList();
                    }
                    catch { }
                }
                else
                {
                    ids.Add(idlocation);
                }
                if (profile == "Conjunto")
                {
                    try
                    {
                        JArray locationsja = JsonConvert.DeserializeObject <JArray>(custom.GetbyCustom("parent", ids, "Locations"));
                        ids.AddRange((from loc in locationsja select(string) loc["_id"]).ToList());
                        // ids = ids.Distinct().ToList();
                    }
                    catch { }
                }
                else
                {
                    if (!ids.Contains(idlocation))
                    {
                        ids.Add(idlocation);
                    }
                }
                try
                {
                    JArray sublocationsja = JsonConvert.DeserializeObject <JArray>(custom.GetbyCustom("parent", ids, "Locations"));
                    ids.AddRange((from loc in sublocationsja select(string) loc["_id"]).ToList());
                    // ids = ids.Distinct().ToList();
                }
                catch { }
            }
            catch { }
            return(ids);
        }
 public EmployeeController()
 {
     //  validatelim = new ValidateLimits();
     validatepermissions  = new validatePermissions();
     employeeprofileTable = new EmployeeProfileTable();
     witnessesModel       = new MongoModel("witnesses");
     _listTable           = new ListTable();
     employeetable        = new EmployeeTable();
     Notificate           = new Notifications();
     _logTable            = new LogBook.Controllers.LogBookController();
     userTable            = new UserTable();
     profileTable         = new ProfileTable();
     listTable            = new ListTable();
 }
Example #7
0
        public string GetObjectsTable(JObject options)
        {
            //Query needed to get the result
            IMongoQuery        query = null, query2;
            List <IMongoQuery> listqueries  = new List <IMongoQuery>();
            List <IMongoQuery> listqueries2 = new List <IMongoQuery>();
            long     dateinit = 0;
            DateTime fecha    = new DateTime();
            int      cantidad;

            if (options["type"].ToString() != "summary")
            {
                int.TryParse(options["date"][0].ToString(), out cantidad);
                if (options["date"][1].ToString() == "minutes")
                {
                    fecha = DateTime.Now.AddMinutes(-cantidad);
                }
                if (options["date"][1].ToString() == "hours")
                {
                    fecha = DateTime.Now.AddHours(-cantidad);
                }
                if (options["date"][1].ToString() == "days")
                {
                    fecha = DateTime.Now.AddDays(-cantidad);
                }

                string cad1 = fecha.ToString("yyyyMMddhhmmss");
                long.TryParse(cad1, out dateinit);
            }

            JObject objfilter   = JsonConvert.DeserializeObject <JObject>(options["filters"].ToString());
            JArray  filters     = JsonConvert.DeserializeObject <JArray>(objfilter["modules"].ToString());
            JArray  valores     = new JArray();
            JObject ObjectsReal = new JObject();

            ObjectsReal["Locations"]        = "location";
            ObjectsReal["ReferenceObjects"] = "objectReference";
            ObjectsReal["Users"]            = "userid";
            MongoModel profdb     = new MongoModel("LocationProfiles");
            MongoModel locationdb = new MongoModel("Locations");

            foreach (JObject filter in filters)
            {
                listqueries2.Clear();
                valores = JsonConvert.DeserializeObject <JArray>(filter["v"].ToString());

                if (valores.Count == 0)
                {
                    continue;
                }
                foreach (String val in valores)
                {
                    try
                    {
                        JObject location = JsonConvert.DeserializeObject <JObject>(locationdb.GetRow(val));
                        JObject profid   = JsonConvert.DeserializeObject <JObject>(profdb.GetRow(location["profileId"].ToString()));
                        if (profid["name"].ToString() != "Sub-Ubicaciones")
                        {
                            List <string> sublocationslist = sublocations(val, profid["name"].ToString());
                            foreach (string sub in sublocationslist)
                            {
                                try
                                {
                                    listqueries2.Add(Query.EQ(ObjectsReal[filter["mod"].ToString()].ToString(), sub));
                                }
                                catch { }
                            }
                        }
                    }
                    catch { }
                    listqueries2.Add(Query.EQ(ObjectsReal[filter["mod"].ToString()].ToString(), val));
                }
                query2 = Query.Or(listqueries2);
                listqueries.Add(query2);
            }
            if (options["type"].ToString() != "summary")
            {
                listqueries.Add(Query.GTE("CreatedTimeStamp", dateinit));
            }

            if (listqueries.Count > 0)
            {
                query = Query.And(listqueries);
            }

            JoinCollections Join = new JoinCollections();

            Join = Join.Select("ObjectReal");
            foreach (JObject filter in filters)
            {
                if (objfilter["group"].ToString() == ObjectsReal[filter["mod"].ToString()].ToString())
                {
                    continue;
                }
                Join = Join.Join(filter["mod"].ToString(), ObjectsReal[filter["mod"].ToString()].ToString(), "_id", "name => " + ObjectsReal[filter["mod"].ToString()].ToString());
            }
            string groupMod = "";

            foreach (KeyValuePair <String, JToken> token in ObjectsReal)
            {
                if (token.Value.ToString() == objfilter["group"].ToString())
                {
                    groupMod = token.Key.ToString();
                }
            }

            Join = Join.Join(groupMod, objfilter["group"].ToString(), "_id", "name => " + ObjectsReal[groupMod].ToString());

            return(Join.Find(query));
        }
 /// <summary>
 /// Login Window Show
 /// </summary>
 /// <returns>Login View</returns>
 /// <author>Galaviz Alejos Luis Angel</author>
 ///
 public LoginController()
 {
     usertable   = new UserTable();
     messagectrl = new MessageController();
     keysTable   = new MongoModel("Keyspwd");
 }
Example #9
0
 public CountryService(MongoModel mongoModel)
 {
     collection = new MongoContext(mongoModel)
                  .database
                  .GetCollection <UserBsonModel>(mongoModel.Collection.User);
 }
Example #10
0
        /// <summary>
        ///     This functions makes the field html string from the array [ _id, position, size, required ]
        /// </summary>
        /// <param name="fieldArray">
        ///     An array in the form [ _id, position, size, required ]
        ///     Where
        ///         _id: is the field's document id in the db,
        ///         position: is 1 for left or 2 for right,
        ///         size: is 1 for half size(50%) or 2 for full size(100%),
        ///         required: is 0 for false or 1 for true
        /// </param>
        /// <param name="owner">
        ///     The collections's field name
        /// </param>
        /// <author>
        ///     Luis Gonzalo Quijada Romero
        /// </author>
        /// <returns>
        ///     Returns the HTML div view from the specified custom field
        /// </returns>
        public static String getFieldView(dynamic fieldArray, String collectionName)
        {
            string            documentId = fieldArray["fieldID"];
            CustomFieldsTable fieldTable;
            JObject           customField;

            try //try to get the field json document if owner and documentId are valid, else fieldView is null
            {
                fieldTable = new CustomFieldsTable(collectionName);
                String customFieldString = fieldTable.GetRow(documentId);
                customField = JsonConvert.DeserializeObject <JObject>(customFieldString);
            }
            catch (Exception e) { return(null); }

            if (customField == null)
            {
                return(null);                     //if customfield id does not exists
            }
            String result = "<div";

            try //trying to assign the class of the customfield view
            {
                result += " class='";
                result += (fieldArray["position"] == 1) ? " fl" : " fr";
                result += (fieldArray["size"] == 1) ? " mediumSize" : " fullSize";
                result += "'>";
            }
            catch (Exception e) { /*Ignored*/ }

            try //trying to draw the label if it exists
            {
                result += "<label>" + customField["label"].ToString() + ": </label><br/>";
            }
            catch (Exception e) { /*Ignored*/ }

            String interText = "";

            //CustomField's specific elements
            switch (customField["type"].ToString())
            {
            case "TextField":
                result += "<input class='customInput2' type='text'";
                try     //trying to set the patter to the field text
                {
                    result += " pattern='" + customField["regularExp"].ToString() + "'";
                }
                catch (Exception e) { /*Ignored*/ }
                try     //trying to set the placeholder to the field text
                {
                    result += " placeholder='" + customField["placeHolder"].ToString() + "'";
                }
                catch (Exception e) { /*Ignored*/ }
                //try //trying to set the maxlenght to the field text
                //{
                //    result += " maxlength='" + customField["maxSize"].ToString() + "'";
                //}catch(Exception e){ /*Ignored*/ }
                break;

            case "CheckBoxField":
                result += "<input class='customInput2' type='checkbox'";
                try     //trying to set the value name to the check box field
                {
                    result += " value='" + customField["name"].ToString() + "'";
                }
                catch (Exception e) { /*Ignored*/ }
                try     //trying to set the checked attribute to those which are pre-selected
                {
                    result += (customField["check"].ToString() == "true" ? " CHECKED" : "");
                }
                catch (Exception e) { /*Ignored*/ }
                break;

            case "CurrencyField":
                try{     //trying to draw the currency symbol before the field
                    result += "<label>" + customField["currencySymbol"].ToString() + "</label>";
                }
                catch (Exception e) { /*Ignored*/ }
                result += " <input class='customInput2' type='number' size='4' step='0.01'";
                try     //trying to set the field default value
                {
                    result += " value='" + customField["defaultValue"].ToString() + "'";
                }
                catch (Exception e) { /*Ignored*/ }
                break;

            case "DateField":
                result += " <input class='customInput2' type='date'";
                try     //trying to set the field default value
                {
                    if (customField["defaultValue"].ToString() == "true")
                    {
                        result += " value='" + DateTime.Today.ToString("yyyy-MM-dd") + "'";
                    }
                }
                catch (Exception e) { /*Ignored*/ }
                break;

            case "DateTimeField":
                result += " <input class='customInput2' type='dateTime-local'";
                try     //trying to set the field default value
                {
                    string defaultValue = "";
                    if (customField["defaultDate"].ToString() == "true")
                    {
                        defaultValue += DateTime.Today.ToString("yyyy-MM-dd");
                    }
                    if (customField["defaultHour"].ToString() == "true")
                    {
                        defaultValue += "T" + DateTime.Now.ToString("HH:mm:ss");
                    }
                    result += " value='" + defaultValue + "'";
                }
                catch (Exception e) { /*Ignored*/ }
                break;

            case "TextAreaField":
                result += " <textarea class='customInput2'";
                try     //trying to draw the placeholder
                {
                    result += " placeholder='" + customField["placeHolder"].ToString() + "'";
                }
                catch (Exception e) { /*Ignored*/ }
                break;

            case "DecimalField":
                result += " <input class='customInput2' type='number'";
                try     //trying to set the field default value
                {
                    result += " value='" + customField["defaultValue"].ToString() + "'";
                }
                catch (Exception e) { /*Ignored*/ }
                try     //trying to set the field max value
                {
                    result += " max='" + customField["maxSize"].ToString() + "'";
                }
                catch (Exception e) { /*Ignored*/ }
                try     //trying to set the field default value
                {
                    result += " step='" + (1d / Math.Pow(10, ((Double)customField["precision"] + 1))).ToString().Replace(",", ".") + "'";
                }
                catch (Exception e) { /*Ignored*/ }
                break;

            case "ImageField":
            case "FileField":
                result += "<img id='_HTKField" + customField["name"].ToString() + "Preview' style='width:100px; height: 100px;'/>";
                result += "<input class='customInput2' type='file'";
                break;

            case "MultiSelectField":
            case "DropDownField":
                result += "<select";
                if (customField["type"].ToString() == "MultiSelectField")
                {
                    result += " multiple";
                }

                MongoModel listModel  = new MongoModel("Lists");
                String     listString = listModel.GetRow(customField["listId"].ToString());
                JObject    list       = (JObject)JsonConvert.DeserializeObject <JObject>(listString)["elements"];
                foreach (JObject element in (JArray)list["order"])
                {
                    foreach (KeyValuePair <String, JToken> token in element)
                    {
                        interText += "<option value='" + token.Key + "'> " + token.Value + "</option>\n";
                        break;
                    }
                }
                interText += "<option disabled='disabled'>---------------------</option>\n";
                foreach (JObject element in (JArray)list["unorder"])
                {
                    foreach (KeyValuePair <String, JToken> token in element)
                    {
                        interText += "<option value='" + token.Key + "'> " + token.Value + "</option>\n";
                        break;
                    }
                }
                break;

            case "RadioField":
                MongoModel listModelRadio  = new MongoModel("Lists");
                String     listStringRadio = listModelRadio.GetRow(customField["listId"].ToString());
                JObject    listRadio       = (JObject)JsonConvert.DeserializeObject <JObject>(listStringRadio)["elements"];
                foreach (JObject element in (JArray)listRadio["order"])
                {
                    foreach (KeyValuePair <String, JToken> token in element)
                    {
                        interText += "<input name='_HTKField" + customField["name"].ToString() + "' id='_HTKField" + customField["name"].ToString() + "' type='radio' value='" + token.Key + "'/>";
                        interText += "<label for = '" + token.Key + "'>" + token.Value + "</label>\n<br/>";
                        break;
                    }
                }
                foreach (JObject element in (JArray)listRadio["unorder"])
                {
                    foreach (KeyValuePair <String, JToken> token in element)
                    {
                        interText += "<input name='_HTKField" + customField["name"].ToString() + "' id='_HTKField" + customField["name"].ToString() + "' type='radio' value='" + token.Key + "'/>";
                        interText += "<label for = '" + token.Key + "'>" + token.Value + "</label>\n<br/>";
                        break;
                    }
                }
                break;

            case "URLField":
                result += "<input type='url'";
                break;

            case "IntegerField":
                result += "<input type='number'";
                break;

            case "PhoneField":
                result += "<input type='tel'";
                break;

            default:
                return(null);
            }

            if (customField["type"].ToString() != "RadioField")
            {
                List <String> hasTooltip = new List <string>()
                {
                    "TextField",
                    "CurrencyField",
                    "DateField",
                    "DateTimeField",
                    "TextAreaField",
                    "DecimalField",
                    "IntegerField",
                    "PhoneField",
                    "URLField"
                };
                if (hasTooltip.Contains(customField["type"].ToString()))
                {
                    try //trying to draw the tooltip
                    {
                        result += " data-original-title='" + customField["toolTip"].ToString() + "' rel='tooltip' data-placement='right'";
                    }
                    catch (Exception e) { /*Ignored*/ }
                }
                try
                { //trying to draw the field name if it can't be set the view must not be generated(name is required for javascript's actions)
                    result += " name='_HTKField" + customField["name"].ToString() + "'";
                }
                catch (Exception e) { return(null); }
                try //trying to draw the field id, if it can't be set, the view must not be genarated(Id is required for javascript's actions)
                {
                    result += " id='_HTKField" + customField["name"].ToString() + "'";
                }
                catch (Exception e) { return(null); }
                try
                {
                    if (fieldArray["required"] == 1) //is this field required?
                    {
                        result += " required";
                    }
                }
                catch (Exception e) { /*Ignored*/ }
                result += ">";
            }
            result += interText;
            if (customField["type"].ToString() == "TextAreaField") //if it's a textarea close the tag
            {
                result += "</textarea>";
            }
            else if (customField["type"].ToString() == "DropDownField" || customField["type"].ToString() == "MultiSelectField")
            {
                result += "</select>";
            }
            result += "</div>"; //end of the field's div

            return(result);
        }
Example #11
0
 public SemaphoreController()
 {
     semaphoredb       = new MongoModel("Semaphore");
     movementprofiledb = new MongoModel("MovementProfiles");
     _logTable         = new LogBook.Controllers.LogBookController();
 }
Example #12
0
 public Notifications()
 {
     notificationsDb = new MongoModel("Notifications");
     push            = new Messenger();
 }
Example #13
0
        public MongoContext(MongoModel mongoModel)
        {
            var client = new MongoClient(mongoModel.Connection);

            database = client.GetDatabase(mongoModel.Database);
        }
        public string validate(String nameCollection, String key = null, String value = null, String mod = null, int numitems = 0, bool filter = false, int getavailables = 0)
        {
            try
            {
                return("true");

                dbMod = new MongoModel(nameCollection);
                String result = "";
                if (key == null || value == null)
                {
                    result = dbMod.GetRows();
                }
                else if (key != null && value != null)
                {
                    if (filter == true)
                    {
                        result = dbMod.Get(key, value);
                    }
                    else
                    {
                        result = dbMod.GetRows();
                    }
                }
                JArray resultja = JsonConvert.DeserializeObject <JArray>(result);
                //   String resultlimit = dbLimits.GetRows();
                //   JArray limitsja = JsonConvert.DeserializeObject<JArray>(resultlimit);
                JObject limitsjo    = new JObject();
                int     counttotals = 0;
                if ((key != null) && filter == false)
                {
                    foreach (JObject item in resultja)
                    {
                        int num = 0;
                        int.TryParse(item[key].ToString(), out num);
                        counttotals = counttotals + num;
                    }
                }
                else
                {
                    counttotals = resultja.Count();
                }

                /*  foreach (JObject item in limitsja)
                 * {
                 *
                 *    limitsjo = item;
                 * }
                 */
                //  int limit = Convert.ToInt32(limitsjo[mod].ToString());
                int limit = Convert.ToInt32(Filelimits["clientInfo"][mod].ToString());
                if (limit < 0)
                {
                    return("true");
                }
                int total      = counttotals;
                int stock      = numitems + total;
                int availables = limit - stock;
                int ac         = limit - total;
                if (ac < 0)
                {
                    ac = 0;
                }
                if (availables < 0)
                {
                    availables = 0;
                }

                if (stock <= limit)
                {
                    return("true");
                }
                else
                {
                    if (getavailables == 1)
                    {
                        return(ac.ToString());
                    }
                    if (numitems > 1)
                    {
                        return("Su solicitud sobrepasa el limite,solo puede crear  " + ac + " ");
                    }
                    return("Ha llegado a su limite permitido,no puede crear más ");
                }
            }
            catch (Exception ex)
            {
                return("false");
            }
        }