Пример #1
0
        /// <summary>
        /// This funtion represts the logic to edit an exsiting dynamic rule which is requested by the user.
        /// </summary>
        /// <param name="dynamic"> Is a refernece of Dynamicrule which helps to access the values stored in the variables of dynamic rule and
        ///                        stores the value entered by a user and other values.</param>
        /// <param name="loggedinUser">The session email of the logged in user (user.identity.name)</param>
        /// <returns>true if the rule is editted and flase when the rule can not be editted</returns>
        public bool EditDynamicRule(DyanamicRule dynamic, string loggedinUser)
        {
            using (var usersDbContext = new UsersEntities())
            {
                string userid = (from row in usersDbContext.AspNetUsers
                                 where row.UserName == loggedinUser
                                 select row.Id).First();

                bool isSaved = false;
                if (dynamic.Query == "" && dynamic.Response == "")
                {
                    return(isSaved);
                }
                else if (dynamic.Query == null && dynamic.Response == null)
                {
                    return(isSaved);
                }
                else
                {
                    using (var context = new UTSDatabaseEntities())
                    {
                        var query_search = (from row in context.DyanamicRules.ToList()
                                            where row.Query == dynamic.Query
                                            select row.Query).FirstOrDefault();
                        if (query_search.ToLower() == dynamic.Query.ToLower())
                        {
                            return(isSaved);
                        }
                        else
                        {
                            var stored   = context.DyanamicRules.Find(dynamic.RuleId);
                            var oldvalue = stored;
                            stored.Status        = RulesStatus.Updated.ToString();
                            stored.Query         = dynamic.Query;
                            stored.Response      = dynamic.Response;
                            stored.Keyword       = dynamic.Keyword;
                            stored.Match         = dynamic.Match;
                            stored.LastUpdatedby = loggedinUser;
                            context.Entry(oldvalue).CurrentValues.SetValues(stored);
                            context.SaveChanges();
                            isSaved = true;
                            return(isSaved);
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// This funtion represts the logic to edit an exsiting fixed rule which is requested by the user.
        /// </summary>
        /// <param name="fixrule"> Is a refernece of Fixedrule which helps to access the values stored in the variables of fixed rule and
        ///                        stores the value entered by a user and other values.</param>
        /// <param name="loggedinUser">The session email of the logged in user (user.identity.name)</param>
        /// <returns>true if the rule is editted and flase when the rule can not be editted</returns>
        public bool EditFixedRule(Fixedrule fixrule, string loggedinUser)
        {
            using (var usersDbContext = new UsersEntities())
            {
                bool   isSaved = false;
                string userid  = (from row in usersDbContext.AspNetUsers
                                  where row.UserName == loggedinUser
                                  select row.Id).First();

                if (fixrule.Query == "" && fixrule.Response == "")
                {
                    return(isSaved);
                }

                /* else if (fixrule.Query == null && fixrule.Response == null)
                 *   return isSaved;*/
                else
                {
                    using (var context = new UTSDatabaseEntities())
                    {
                        var query_search = (from row in context.Fixedrules
                                            where row.Query == fixrule.Query
                                            select row.Query).FirstOrDefault();


                        if (query_search.ToLower() == fixrule.Query.ToLower())
                        {
                            return(isSaved);
                        }
                        else
                        {
                            var stored   = context.Fixedrules.Find(fixrule.RuleId);
                            var oldvalue = stored;
                            stored.Status        = RulesStatus.Updated.ToString();
                            stored.Query         = fixrule.Query;
                            stored.Response      = fixrule.Response;
                            stored.LastUpdatedby = loggedinUser;
                            context.Entry(oldvalue).CurrentValues.SetValues(stored);
                            context.SaveChanges();
                            isSaved = true;
                            return(isSaved);
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Domain logic of Editting datatable entry
        /// </summary>
        /// <param name="topicInformation">The refernce to access topic information for editting it</param>
        /// <param name="loggedinUser">The session of user that is logged in.</param>
        /// <returns></returns>
        public bool EditData(TopicInformation topicInformation, string loggedinUser)
        {
            using (var context = new UTSDatabaseEntities())
            {
                var key = context.TopicInfo.Where(m => m.WeekNumber == topicInformation.WeekNumber).FirstOrDefault();

                if (key != null)
                {
                    topicInformation.LastUpdatedBy   = loggedinUser;
                    db.Entry(topicInformation).State = EntityState.Modified;
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }