Пример #1
0
 public static ApplicationReferenceViewModel ToViewModel(ApplicationReferences entity)
 {
     return(new ApplicationReferenceViewModel
     {
         Id = entity.Id,
         Alias = entity.Alias,
         Key = entity.Key,
         ParentId = entity.ParentId,
         Name = entity.Name,
         Value = entity.Value,
         IsParent = entity.IsParent,
         IsDelete = entity.IsDelete,
         IsActive = entity.IsActive,
     });
 }
Пример #2
0
        private static void ReferencesInit(AppContext context)
        {
            var newsTags = new ApplicationReferences
            {
                Alias    = AppConstants._NewsTags,
                Name     = AppConstants._NewsTags,
                IsParent = true,
                Value    = AppConstants._NewsTags,
                Key      = AppConstants._NewsTags,
                IsActive = true
            };

            context.ApplicationReferences.Add(newsTags);

            context.SaveChanges();
        }
Пример #3
0
        public IEnumerable <Article> Get(string tagAlias)
        {
            IEnumerable <Article> news = null;

            try
            {
                var ctx = unitOfWork.CityLifeDbContext;

                if (string.IsNullOrEmpty(tagAlias))
                {
                    news = ctx.Set <Article>()
                           .Include(x => x.Tags)
                           .Include(x => x.PreviewPictures)
                           .Include(x => x.Owner)
                           .ToList();
                }
                else
                {
                    ApplicationReferences tag = ctx
                                                .Set <ApplicationReferences>()
                                                .FirstOrDefault(x => x.Alias.ToLower() == tagAlias);

                    if (tag == null)
                    {
                        return(null);
                    }

                    news = ctx.Set <Article>()
                           .Include(x => x.Tags)
                           .Include(x => x.PreviewPictures)
                           .Include(x => x.Owner)
                           .Where(x => x.Tags.Any(y => y.Id == tag.Id))
                           .ToList();
                }
                return(news);
            }
            catch (Exception ex)
            {
                ExceptionService.WriteException(ex, section, SysConstants.AppException_CityNews);
                throw new Exception(ex.Message);
            }
        }
Пример #4
0
        public ApplicationReferences Edit(ApplicationReferences entity)
        {
            try
            {
                var editEntity = new ApplicationReferences();

                if (entity != null)
                {
                    var ctx = unitOfWork
                              .CityLifeDbContext;

                    DbSet <ApplicationReferences> set = ctx.Set <ApplicationReferences>();

                    if (entity.Id == 0)
                    {
                        repository.Add(editEntity);
                    }
                    else
                    {
                        editEntity = set.FirstOrDefault(x => x.Id == editEntity.Id);
                    }

                    editEntity.IsParent = entity.IsParent;
                    editEntity.ParentId = entity.ParentId;
                    editEntity.Name     = entity.Name;
                    editEntity.Alias    = entity.Name.ToAlias();
                    editEntity.IsActive = entity.IsActive;

                    editEntity.Key   = entity.Key;
                    editEntity.Value = entity.Value;

                    ctx.SaveChanges();
                }

                return(editEntity);
            }
            catch (Exception ex)
            {
                ExceptionService.WriteException(ex, section, SysConstants.AppException_References);
                throw new Exception(ex.Message);
            }
        }
Пример #5
0
        public ApplicationReferences GetById(int id)
        {
            try
            {
                ApplicationReferences entity = null;

                if (id != 0)
                {
                    var ctx = unitOfWork.CityLifeDbContext;

                    entity = ctx.Set <ApplicationReferences>()
                             .FirstOrDefault(x => x.Id == id);

                    return(entity);
                }

                return(entity);
            }
            catch (Exception ex)
            {
                ExceptionService.WriteException(ex, section, SysConstants.AppException_References);
                throw new Exception(ex.Message);
            }
        }
Пример #6
0
        public Article Edit(Article entry, int[] tagIdentifiers)
        {
            try
            {
                Article entity = new Article();

                using (var ctx = unitOfWork.CityLifeDbContext)
                {
                    var artSet = ctx.Set <Article>();

                    if (entry.Id > 0)
                    {
                        entity = artSet
                                 .Include(x => x.Tags)
                                 .Include(x => x.PreviewPictures)
                                 .Include(x => x.Owner)
                                 .FirstOrDefault(x => x.Id == entry.Id);
                    }
                    else
                    {
                        artSet.Add(entry);
                    }


                    entity.MetaKeywords    = entry.MetaKeywords;
                    entity.MetaDescription = entry.MetaDescription;

                    entity.Name  = entry.Name;
                    entity.Alias = entry.Name.ToAlias();

                    entry.DateUpdate        = DateTime.Now;
                    entity.Content          = entry.Content;
                    entity.ShortDescription = entry.ShortDescription;
                    entity.OwnerId          = entity.OwnerId;

                    entity.IsActive = entry.IsActive;
                    entity.IsDelete = entry.IsDelete;

                    entity.PathPreviewPic = entry.PathPreviewPic;
                    entity.PathTitlePic   = entry.PathTitlePic;


                    entity.Tags.Clear();

                    foreach (int tagId in tagIdentifiers)
                    {
                        ApplicationReferences tag = ctx.Set <ApplicationReferences>()
                                                    .FirstOrDefault(x => x.Id == tagId);
                        entity.Tags.Add(tag);
                    }

                    ctx.SaveChanges();
                }

                return(entity);
            }
            catch (Exception ex)
            {
                ExceptionService.WriteException(ex, section, SysConstants.AppException_CityNews);
                throw new Exception(ex.Message);
            }
        }