Пример #1
0
        public static Operation Add(FAQEntry model)
        {
            try
            {
                model.Status = Models.Enums.RecordStatus.Active;
                db.FAQEntries.Add(model);
                db.SaveChanges();

                return(new Operation()
                {
                    Code = "Ok",
                    Message = new List <string>()
                    {
                        "FAQ is created successfully."
                    }
                });
            }
            catch (Exception e)
            {
                return(new Operation()
                {
                    Code = "Fail",
                    Message = new List <string>()
                    {
                        e.Message
                    }
                });
            }
        }
Пример #2
0
        public static Operation Create(FAQEntry model)
        {
            try
            {
                db.FAQEntries.Add(model);
                db.SaveChanges();

                return(new Operation()
                {
                    Code = "Ok",
                    Message = new List <string>()
                    {
                        "FAQ is created successfully."
                    }
                });
            }
            catch (Exception e)
            {
                return(new Operation()
                {
                    Code = "Fail",
                    Message = new List <string>()
                    {
                        e.Message
                    }
                });
            }
        }
Пример #3
0
        public static Operation Update(FAQEntry model)
        {
            try
            {
                FAQEntry faqentryRecord = db.FAQEntries.FirstOrDefault(s => s.Id == model.Id);

                if (faqentryRecord != null)
                {
                    faqentryRecord.Question = model.Question;
                    faqentryRecord.Answer   = model.Answer;
                    db.SaveChanges();

                    return(new Operation()
                    {
                        Code = "Ok",
                        Message = new List <string>()
                        {
                            " FAQ is updated successfully."
                        }
                    });
                }

                return(new Operation()
                {
                    Code = "Ok",
                    Message = new List <string>()
                    {
                        "FAQ not Found"
                    }
                });
            }
            catch (Exception e)
            {
                return(new Operation()
                {
                    Code = "Fail",
                    Message = new List <string>()
                    {
                        e.Message
                    }
                });
            }
        }
Пример #4
0
        public static Operation Delete(FAQEntry model)
        {
            try
            {
                FAQEntry faqentryRecord = db.FAQEntries.FirstOrDefault(s => s.Id == model.Id);

                if (faqentryRecord != null)
                {
                    model.Status = Models.Enums.RecordStatus.Inactive;
                    db.SaveChanges();

                    return(new Operation()
                    {
                        Code = "Ok",
                        Message = new List <string>()
                        {
                            " FAQ is Deleted successfully."
                        }
                    });
                }

                return(new Operation()
                {
                    Code = "Ok",
                    Message = new List <string>()
                    {
                        "FAQ not Found"
                    }
                });
            }
            catch (Exception e)
            {
                return(new Operation()
                {
                    Code = "Fail",
                    Message = new List <string>()
                    {
                        e.Message
                    }
                });
            }
        }
Пример #5
0
        private IEnumerable <FAQEntry> CreateFAQEntriesFromFile(string linesInFile)
        {
            var faqs  = new List <FAQEntry>();
            var lines = from line in linesInFile.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                        select line.Split('\t').ToArray();

            // parser header
            var headerDic = ParserHeader(lines.ElementAt(0));

            foreach (var line in lines.Skip(1))
            {
                FAQEntry entry = new FAQEntry()
                {
                    Question = line[headerDic[nameof(FAQEntry.Question).ToUpper()]],
                    Answer   = line[headerDic[nameof(FAQEntry.Answer).ToUpper()]],
                    Source   = line[headerDic[nameof(FAQEntry.Source).ToUpper()]],
                    Metadata = line[headerDic[nameof(FAQEntry.Metadata).ToUpper()]]
                };

                faqs.Add(entry);
            }

            return(faqs);
        }