private static XmlDocument GetXml(EN_EventType type, EN_SubType nodeType)
        {
            XmlDocument doc;

            // get from cache
            if (Global.Cache.dicEventTemplates.ContainsKey(type))
            {
                doc = Global.Cache.dicEventTemplates[type];
            }
            else
            {
                doc = GetFullXml(type);
            }                           // Full document
            //
            var elem = doc.DocumentElement.SelectSingleNode(GetXmlNodeName(nodeType));

            // recreate full
            doc = new XmlDocument();
            // remove comments
            var content = new Regex(" < !--[\\w\\s]*-->|<!---->").Replace(elem.OuterXml, "");

            doc.LoadXml(content);
            // return rezult
            return(doc);
        }
 private static List <DTO_KeyItem> GetKeyList(EN_EventType type, EN_SubType nodeType)
 {
     return(GetXml(type, nodeType).DocumentElement       // get main element
            .SelectNodes("//key").Cast <XmlElement>()    // cast
            .Select(a => new DTO_KeyItem(a))             // get keyItem
            .Where(a => a.Enable).ToList());             // selecn active
 }
        public EventModel(Dictionary <string, string> dic, EN_EventType Type)
        {
            if (!EventTemplate.HasTemplate(Type))
            {
                throw new ExodusException("Template not found");
            }
            //
            Init(Type);
            // check keys
            var keys = CheckKeys(dic);

            // fill model
            FieldModel(keys);
            // Get Content
            Content = EventTemplate.GetContent(keys, Type);
            // Get ThumbNail
            Thumbnail = EventTemplate.GetThumbnail(Models, Type);
            // Add Event
            EventID = _DL.Events.Add.Event(this.Event);
            // Add Relations
            if (this.EventID != -1)
            {
                _DL.Events.Add.EventToUsers(this.EventID, RelatedUsers);
            }
        }
Example #4
0
 public static VM_EventTemplate EventTemplate_ByEventTypeID(EN_EventType EventType)
 {
     using (var exodusDB = new exodusEntities())
     {
         var rez = exodusDB.stp_EventTemplate_ByEventTypeID(EventType.ToInt()).FirstOrDefault();
         if (rez != null)
         {
             var template = new VM_EventTemplate()
             {
                 eventType = new VM_EventType()
                 {
                     ID = rez.fk_EventTypeID
                 },
                 ID       = rez.EventTemplateID,
                 TitleEng = rez.EventTitleEng,
                 TitleRus = rez.EventTitleRus
             };
             // Create XML
             template.Content.LoadXml(rez.EventContent);
             template.Thumbnail.LoadXml(rez.EventThumbnail);
             // return template
             return(template);
         }
         else
         {
             return(null);
         }
     }
 }
        public static List <DTO_KeyItem> GetKeyItemsContent(EN_EventType type)
        {
            // get content
            XmlDocument doc = GetXml(type, EN_SubType.Content);

            // fiil document
            return(doc.SelectNodes("//key").Cast <XmlElement>().Select(a => new DTO_KeyItem(a)).ToList());
        }
Example #6
0
 public API_Response <long> Add(Dictionary <string, string> dic, [FromUri] EN_EventType type, [FromUri] string api_key = null)
 {
     return(InvokeAPI(() =>
     {
         var _event = new EventModel(dic, type);
         //
         return _event.EventID;
     }, api_key));
 }
        public static XmlDocument GetThumbnail(List <DTO_ModelObject> Models, EN_EventType type)
        {
            // get content
            XmlDocument doc = GetXml(type, EN_SubType.Thumbnail);

            // fiil document
            foreach (XmlElement item in doc.SelectNodes("//key"))
            {
                var keyItem = new DTO_KeyItem(item);
                var model   = Models.Where(a => a.Name == keyItem.ModelName).FirstOrDefault().Model;
                //
                if (model.GetType().Name == keyItem.Model)
                {
                    // set name
                    item.SetAttribute("name", keyItem.Name);
                    // get property
                    switch (keyItem.PropertyName.ToLower())
                    {
                    case "avatarsmall": item.SetAttribute("value", $"{model.GetType().GetProperty("UserID").GetValue(model)}"); break;

                    case "avatarbig": item.SetAttribute("value", $"{model.GetType().GetProperty("UserID").GetValue(model)}");   break;

                    default:
                        var value = model.GetType().GetProperty(keyItem.PropertyName).GetValue(model);
                        if (keyItem.ModelType == EN_ModelType.Class)
                        {
                            var dicString = ((IDictionarySerialozation)value).DictionarySerialozation.Select(a => $"\"{a.Key}\":\"{a.Value}\"");
                            item.SetAttribute("value", String.Join(",", dicString));
                        }
                        else
                        {
                            if (value is decimal)
                            {
                                item.SetAttribute("value", ((decimal)value).ToString("F2").Replace(".", ","));
                            }
                            else if (value is double)
                            {
                                item.SetAttribute("value", ((double)value).ToString("F2").Replace(".", ","));
                            }
                            else if (value is float)
                            {
                                item.SetAttribute("value", ((float)value).ToString("F2").Replace(".", ","));
                            }
                            else
                            {
                                item.SetAttribute("value", value.ToString());
                            }
                        }
                        break;
                    }
                }
            }
            // return document
            return(doc);
        }
        public static List <DTO_KeyItem> GetRelated(List <DTO_ModelObject> Models, EN_EventType type)
        {
            var list = GetKeyList(type, EN_SubType.Related);

            //
            for (int i = 0; i < list.Count; i++)
            {
                var model = Models.Where(a => a.Name == list[i].ModelName).FirstOrDefault().Model;
                var value = model.GetType().GetProperty(list[i].PropertyName).GetValue(model);
                list[i].Value = value.ToString();
            }
            //
            return(list);
        }
 public static bool HasTemplate(EN_EventType type)
 {
     if (Global.Cache.dicEventTemplates.ContainsKey(type))
     {
         return(true);
     }
     else
     {
         // Get name by id
         string fName = FileHelper.GetFileList(xmlFolderName)
                        .Where(a => new FileInfo(a).Name.StartsWith($"{type.ToInt()}_")).FirstOrDefault();
         // Has template
         return(File.Exists(fName));
     }
 }
        private static XmlDocument GetXmlNameValue(List <DTO_KeyItem> keyItems, EN_EventType type, EN_SubType nodeType)
        {
            // get content
            XmlDocument doc = GetXml(type, nodeType);

            // fiil document
            foreach (XmlElement item in doc.SelectNodes("//key"))
            {
                // get keyItem
                var keyItem = keyItems.Where(a => a.Name == item.GetAttribute("name")).FirstOrDefault();
                item.SetAttribute("name", keyItem.Name);
                item.SetAttribute("value", keyItem.ValueString);
            }
            // return document
            return(doc);
        }
        public static XmlDocument GetFullXml(EN_EventType type)
        {
            // Get name by id
            string fName = FileHelper.GetFileList(xmlFolderName)
                           .Where(a => new FileInfo(a).Name.StartsWith($"{type.ToInt()}_")).FirstOrDefault();
            // create Xml
            XmlDocument doc = new XmlDocument();

            doc.Load(fName);
            //
            string content = XmlNodeAttributeToLower(doc.OuterXml);

            //
            doc.LoadXml(content);
            // return
            return(doc);
        }
 public API_Response <long> ToObligation(long IntentionID, [FromUri] string api_key = null)
 {
     return(InvokeAPI(() =>
     {
         var intention = _DL.Intention.Get.ByID(IntentionID);
         //
         if (intention == null)
         {
             throw new IntentionNotFoundException();
         }
         else
         {
             var rez = _DL.Intention.To.Obligation(IntentionID);
             //
             var obligation = _DL.Obligation.Get.ByID(rez);
             if ((intention.Period == EN_Period.Undefined || intention.Period == EN_Period.Once) && rez > 0)
             {
                 _DL.Intention.Delete.ByID(IntentionID);
             }
             //
             var tag = _DL.Tag.Get.ByID(obligation.ObligationTag.TagID);
             decimal totalSum = _DL.Obligation.Get.Obligation_Sum_ByTagID(tag.TagID);
             // If total amount bigger then tag amount
             if (totalSum >= tag.TotalAmount && tag.ApplicationType == EN_ApplicationType.Own_Initiative)
             {
                 Dictionary <string, string> dic = new Dictionary <string, string>();
                 EN_EventType type = EN_EventType.Own_Initiative_Tag_Reached_Target_Amount;
                 // Add Keys
                 dic.Add("TagID", tag.TagID.ToString());
                 // Create new event
                 new EventModel(dic, type);
             }
             //
             return rez;
         }
     }, api_key));
 }
 public API_Response <long> Add([FromBody] DTO_Intention model, [FromUri] string api_key = null)
 {
     return(InvokeAPI(() =>
     {
         if (!Global.Cache.CheckTagExists(model.TagID))
         {
             throw new TagNotFoundException();
         }
         if (!Global.Cache.CheckUserExists(model.HolderUserID, model.IssuerUserID))
         {
             throw new UserNotFoundException();
         }
         // Validate Input data
         model.ValidateData(isNew: true);
         //
         var rez = _DL.Intention.Add.Intention(model.ViewModel);
         if (rez > 0 && _DL.Tag.Get.Role(model.TagID, model.IssuerUserID) == EN_TagRole.None)
         {
             _DL.Tag.Add.AddUser(model.TagID, (int)EN_TagRole.Member, model.IssuerUserID);
         }
         // Total Summ
         var tag = _DL.Tag.Get.ByID(model.TagID);
         decimal totalSum = _DL.Intention.Get.Intention_Sum_ByTagID(tag.TagID) + _DL.Obligation.Get.Obligation_Sum_ByTagID(tag.TagID);
         // If total amount bigger then tag amount
         if (totalSum >= tag.TotalAmount && tag.ApplicationType == EN_ApplicationType.Own_Initiative)
         {
             Dictionary <string, string> dic = new Dictionary <string, string>();
             EN_EventType type = EN_EventType.Own_Initiative_Tag_Reached_Target_Amount_Including_Intentions;
             // Add Keys
             dic.Add("TagID", tag.TagID.ToString());
             // Create new event
             new EventModel(dic, type);
         }
         //
         return rez;
     }, api_key));
 }
        public static List <DTO_KeyItem> CheckContentKeys(Dictionary <string, string> dic, EN_EventType type, out List <string> incorrectKeys)
        {
            List <DTO_KeyItem> keyItems = new List <DTO_KeyItem>();

            // key item
            incorrectKeys = new List <string>();
            //
            foreach (var keyItem in GetKeyList(type, EN_SubType.Content))
            {
                // if not found
                if (!dic.ContainsKey(keyItem.Name))
                {
                    incorrectKeys.Add(keyItem.Name);
                }
                else
                {
                    keyItem.Value = dic[keyItem.Name]; // Init value
                    // check
                    if (!keyItem.isChecked)
                    {
                        incorrectKeys.Add(keyItem.Name);
                    }
                    else
                    {
                        keyItems.Add(keyItem);
                    }
                }
            }
            // if zero return true
            return(keyItems);
        }
Example #15
0
 // Functions
 protected void Init(EN_EventType Type)
 {
     this.Type           = Type;
     this.Category       = Global.Cache.dicEventTypes[Type].Category;
     this.ImportantLevel = Global.Cache.dicEventTypes[Type].ImportantLevel;
 }
Example #16
0
        public ActionResult Join(VM_TagJoinDetails tagJoinDetails)
        {
            // User
            var user = _DL.User.Get.ByID(tagJoinDetails.UserID);

            if (user == null)
            {
                return(RedirectToAction("UserNotFound", "Errors"));
            }
            // Tag
            var tag = _DL.Tag.Get.ByID(tagJoinDetails.TagID);

            if (tag == null)
            {
                return(RedirectToAction("TagNotFound", "Errors"));
            }
            // If Exists
            if (_DL.Tag.Get.ByUserID(CurrentUser.UserID).Where(a => a.TagID == tagJoinDetails.TagID).Count() != 0 || user.UserID == CurrentUser.UserID)
            {
                return(RedirectToAction("TagCanNotAddYourSelf", "Errors",
                                        new
                {
                    backurl = this.Url.Action("OpenTag", "Desktop", new { TagID = tagJoinDetails.TagID })
                }));
            }
            else
            {
                //
                VM_Intention intention = new VM_Intention()
                {
                    CurrencyID      = tagJoinDetails.IntentionCurrencyID,
                    IntentionAmount = tagJoinDetails.IntentionAmount,
                    ObligationType  = new VM_ObligationType {
                        ObligationTypeID = EN_ObligationType.Money
                    },
                    ObligationKind       = _DL.Obligation.Get.KindDefault_ByAppID(tag.ApplicationID),
                    Period               = tagJoinDetails.Period,
                    IntentionTerm        = tagJoinDetails.IntentionTerm,
                    IntentionIssuer      = CurrentUser,
                    IntentionHolder      = user,
                    IntentionTag         = tag,
                    IntentionApplication = new VM_Application {
                        ApplicationID = tag.ApplicationID
                    },
                    IntentionDurationMonths = 0,
                    IntentionStartDate      = DateTime.Now,
                    IntentionEndDate        = tag.EndDate,
                    IntentionIsActive       = true,
                    IntentionDayOfMonth     = tag.DayOfMonth,
                    IntentionDayOfWeek      = tag.DayOfWeek,
                };
                //
                long rezIntention = _DL.Intention.Add.Intention(intention);
                long rezAdd       = _DL.Tag.Add.AddUserAsMember(tag.TagID, CurrentUser.UserID);
                //
                decimal totalSum = _DL.Intention.Get.Intention_Sum_ByTagID(tag.TagID);
                // If total amount bigger then tag amount
                if (totalSum >= tag.TotalAmount && tag.ApplicationType == EN_ApplicationType.Own_Initiative)
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    EN_EventType type = EN_EventType.Own_Initiative_Tag_Reached_Target_Amount_Including_Intentions;
                    // Add Keys
                    dic.Add("TagID", tag.TagID.ToString());
                    // Create new event
                    new EventModel(dic, type);
                }
                //
                if (_DL.Events.Get.ByID(tagJoinDetails.EventID) != null)
                {
                    // Set Event Read
                    _DL.Events.Update.MarkETU_Processed(CurrentUser.UserID, tagJoinDetails.EventID);
                }
                //
                EventCreator.UserHasJoinedTagUponYourInvitation(tag.TagID, CurrentUser.UserID, tagJoinDetails.UserID, tag.ApplicationID);
                //
                return(RedirectToAction("Index", "Desktop", new { TagID = tag.TagID }));
            }
        }
 public static XmlDocument GetContent(List <DTO_KeyItem> keyItems, EN_EventType type)
 {
     return(GetXmlNameValue(keyItems, type, EN_SubType.Content));
 }