コード例 #1
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            try
            {
                using (TutorialsMngEntities context = CreateContext())
                {
                    Tutorials dbItem = context.Tutorials.FirstOrDefault(o => o.ID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Tutorial not found!";
                        return(false);
                    }
                    else
                    {
                        context.Tutorials.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
コード例 #2
0
        public override DTO.Tutorials.EditFormData GetData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.Tutorials.EditFormData data = new DTO.Tutorials.EditFormData();
            data.Data = new DTO.Tutorials.Tutorials();

            //try to get data
            try
            {
                using (TutorialsMngEntities context = CreateContext())
                {
                    data.Data = convertor.DB2DTO_Tutorial(context.TutorialsList_View.FirstOrDefault(o => o.ID == id));
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
            //  throw new NotImplementedException();
        }
コード例 #3
0
        public override DTO.Tutorials.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.Tutorials.SearchFormData data = new DTO.Tutorials.SearchFormData();
            data.Data = new List <DTO.Tutorials.Tutorials>();
            totalRows = 0;


            //string Name = null;

            //if (filters.ContainsKey("Name") && !string.IsNullOrEmpty(filters["Name"].ToString()))
            //{
            //    Name = filters["Name"].ToString().Replace("'", "''");
            //}



            //try to get data
            try
            {
                using (TutorialsMngEntities context = CreateContext())
                {
                    totalRows = context.TutorialsMng_function_getTutorials().Count();
                    var result = context.TutorialsMng_function_getTutorials();
                    data.Data = convertor.DB2DTO_TutorialSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
コード例 #4
0
        public override bool UpdateData(int id, ref DTO.Tutorials.Tutorials dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int    number;
            string indexName;

            try
            {
                using (TutorialsMngEntities context = CreateContext())
                {
                    Tutorials dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new Tutorials();
                        context.Tutorials.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Tutorials.FirstOrDefault(o => o.ID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Tutorial not found!";
                        return(false);
                    }
                    else
                    {
                        convertor.DTO2BD_Tutorial(dtoItem, ref dbItem);
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.ID, out notification).Data;

                        return(true);
                    }
                }
            }
            catch (System.Data.DataException dEx)
            {
                notification.Type = Library.DTO.NotificationType.Error;
                Library.ErrorHelper.DataExceptionParser(dEx, out number, out indexName);
                if (number == 2601 && !string.IsNullOrEmpty(indexName))
                {
                    if (indexName == "TutorialNameUnique")
                    {
                        notification.Message = "The Tutorial Name already exists";
                    }
                }
                else
                {
                    notification.Message = dEx.Message;
                }

                return(false);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }