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);
            }
        }
 public void DTO2BD_Tutorial(DTO.Tutorials.Tutorials dtoItem, ref Tutorials dbItem)
 {
     AutoMapper.Mapper.Map <DTO.Tutorials.Tutorials, Tutorials>(dtoItem, dbItem);
 }
        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);
            }
        }