Beispiel #1
0
        public JsonResult List(PublicationListArgs args)
        {
            using (var dbc = new KuLibDbContext())
            {
                //var filteredQuery = dbc.Publications
                //    .Where(x => string.IsNullOrEmpty(args.InfoStrFilter) || x.InfoStr.Contains(args.InfoStrFilter));
                IQueryable <Publication> filteredQuery = dbc.Publications;
                if (!string.IsNullOrEmpty(args.InfoStrFilter))
                {
                    filteredQuery = filteredQuery.Where(x => x.InfoStr.Contains(args.InfoStrFilter));
                }

                var data = filteredQuery
                           .OrderBy(x => x.InfoStr)
                           .Page(args)
                           .Select(x => new PublicationListDto
                {
                    Id      = x.Id,
                    InfoStr = x.InfoStr,
                    Year    = x.Year,
                    PublicationInstancesCount     = x.PublicationInstances.Count(),
                    FreePublicationInstancesCount = x.PublicationInstances.Where(y => y.RentingUser == null).Count()
                }).ToArray();

                return(Json(new
                {
                    success = true,
                    data = data,
                    total = filteredQuery.Count()
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public void Update(PublicationInstanceEditDto model)
        {
            using (var dbc = new KuLibDbContext())
            {
                var entity = dbc.PublicationInstances.Find(model.Id);

                if (model.UserId.HasValue && model.UserId.Value != 0)
                {
                    entity.RentingUser = dbc.Users.Find(model.UserId.Value);
                    if (model.ReturnDate.HasValue)
                    {
                        entity.ReturnDate = model.ReturnDate;
                    }
                    else
                    {
                        throw new Exception("При выдаче экземпляра читателю на руки необходимо заполнить дату возврата.");
                    }
                }
                else
                {
                    dbc.Entry(entity).Reference(x => x.RentingUser).Load();
                    entity.RentingUser = null;
                    entity.ReturnDate  = null;
                }

                dbc.SaveChanges();
            }
        }
Beispiel #3
0
        public JsonResult Get(long id)
        {
            try
            {
                using (var dbc = new KuLibDbContext())
                {
                    var entity  = dbc.Publications.Find(id);
                    var service = GetService(entity);
                    var data    = service.Project(entity);

                    return(Json(new
                    {
                        success = true,
                        data = data
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    success = false,
                    message = ex.Message
                }));
            }
        }
Beispiel #4
0
        public JsonResult Delete(long id)
        {
            try
            {
                using (var dbc = new KuLibDbContext())
                {
                    var entity = dbc.Publications.Find(id);
                    dbc.Publications.Remove(entity);

                    dbc.SaveChanges();

                    return(Json(new
                    {
                        success = true
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    success = false,
                    message = ex.Message
                }));
            }
        }
        public JsonNetResult List(PublicationInstanceListArgs args)
        {
            using (var dbc = new KuLibDbContext())
            {
                var filteredQuery = dbc.PublicationInstances
                                    .Where(x => !args.PublicationId.HasValue || args.PublicationId.Value == x.Publication.Id)
                                    .Where(x => !args.UserId.HasValue || args.UserId.Value == x.RentingUser.Id);
                var data = filteredQuery
                           .OrderBy(x => x.Id)
                           .Page(args)
                           .Select(x => new PublicationInstanceListDto
                {
                    Id                 = x.Id,
                    PublicationId      = x.Publication.Id,
                    PublicationInfoStr = x.Publication.InfoStr,
                    UserId             = x.RentingUser.Id,
                    UserShortName      = x.RentingUser.ShortName,
                    ReturnDate         = x.ReturnDate
                }).ToArray();

                return(new JsonNetResult()
                {
                    Data = new
                    {
                        data = data,
                        total = filteredQuery.Count(),
                        success = true,
                    }
                });
            }
        }
 public void Delete(long id)
 {
     using (var dbc = new KuLibDbContext())
     {
         var entity = dbc.PublicationInstances.Find(id);
         dbc.PublicationInstances.Remove(entity);
         dbc.SaveChanges();
     }
 }
Beispiel #7
0
        /// <summary>
        /// Метод редактирования публикации
        /// </summary>
        /// <param name="model"></param>
        public void Update(TEditDto model)
        {
            using (var dbc = new KuLibDbContext())
            {
                var entity = GetSet(dbc).Find(model.Id);
                FillFromModel(entity, model);

                dbc.SaveChanges();
            }
        }
Beispiel #8
0
        /// <summary>
        /// Метод редактирования читателя
        /// </summary>
        /// <param name="model"></param>
        public void Update(UserEditDto model)
        {
            using (var dbc = new KuLibDbContext())
            {
                var user = dbc.Users.Find(model.Id);
                FillFromModel(user, model);

                dbc.SaveChanges();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Метод удаления читателя
        /// </summary>
        /// <param name="id"></param>
        public void Delete(long id)
        {
            using (var dbc = new KuLibDbContext())
            {
                var user = dbc.Users.Find(id);
                dbc.Users.Remove(user);

                dbc.SaveChanges();
            }
        }
Beispiel #10
0
        /// <summary>
        /// Метод получения модели публикации
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public TEditDto Get(long id)
        {
            using (var dbc = new KuLibDbContext())
            {
                var entity = GetSet(dbc).Find(id);
                var model  = new TEditDto();
                FillFromEntity(model, entity);

                return(model);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Метод удаления публикации
        /// </summary>
        /// <param name="id"></param>
        public void Delete(long id)
        {
            using (var dbc = new KuLibDbContext())
            {
                var set    = GetSet(dbc);
                var entity = set.Find(id);
                set.Remove(entity);

                dbc.SaveChanges();
            }
        }
        public PublicationInstance Create(PublicationInstanceEditDto model)
        {
            using (var dbc = new KuLibDbContext())
            {
                var newEntity = new PublicationInstance();
                newEntity.Publication = dbc.Publications.Find(model.PublicationId);
                dbc.PublicationInstances.Add(newEntity);
                dbc.SaveChanges();

                return(newEntity);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Метод создания новой публикации
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public TEntity Create(TEditDto model)
        {
            using (var dbc = new KuLibDbContext())
            {
                var newEntity = new TEntity();
                FillFromModel(newEntity, model);

                GetSet(dbc).Add(newEntity);
                dbc.SaveChanges();

                return(newEntity);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Метод создания нового читателя
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public User Create(UserEditDto model)
        {
            using (var dbc = new KuLibDbContext())
            {
                var newUser = new User();
                FillFromModel(newUser, model);

                dbc.Users.Add(newUser);
                dbc.SaveChanges();

                return(newUser);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Метод получения модели читателя
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public UserEditDto Get(long id)
        {
            using (var dbc = new KuLibDbContext())
            {
                var user  = dbc.Users.Find(id);
                var model = new UserEditDto
                {
                    Id         = user.Id,
                    Name       = user.Name,
                    Surname    = user.Surname,
                    Patronymic = user.Patronymic,
                    FullName   = user.FullName,
                    BirthDate  = user.BirthDate,
                };

                return(model);
            }
        }
        public PublicationInstanceEditDto Get(long id)
        {
            using (var dbc = new KuLibDbContext())
            {
                var entity = dbc.PublicationInstances.Find(id);
                var model  = new PublicationInstanceEditDto()
                {
                    Id                 = entity.Id,
                    PublicationId      = entity.Publication.Id,
                    PublicationInfoStr = entity.Publication.InfoStr,
                    UserId             = entity.RentingUser?.Id,
                    UserShortName      = entity.RentingUser?.ShortName,
                    ReturnDate         = entity.ReturnDate
                };

                return(model);
            }
        }
Beispiel #17
0
        public JsonNetResult List(UserListArgs args)
        {
            using (var dbc = new KuLibDbContext())
            {
                var currentDate = DateTime.Now;
                //var filteredQuery = dbc.Users.Select(x => x);
                IQueryable <User> filteredQuery = dbc.Users;

                if (!string.IsNullOrEmpty(args.query))
                {
                    filteredQuery = filteredQuery.Where(x => x.FullName.Contains(args.query));
                }

                if (args.HasExpired)
                {
                    filteredQuery = filteredQuery.Where(x => x.RentedPublications.Where(y => y.ReturnDate < currentDate).Count() > 0);
                }


                var data = filteredQuery
                           .OrderBy(x => x.FullName)
                           .Page(args)
                           .Select(x => new UserListDto
                {
                    Id           = x.Id,
                    FullName     = x.FullName,
                    BirthDate    = x.BirthDate,
                    RentedCount  = x.RentedPublications.Count(),
                    ExpiredCount = x.RentedPublications.Where(y => y.ReturnDate < currentDate).Count()
                }).ToArray();

                return(new JsonNetResult()
                {
                    Data = new
                    {
                        data = data,
                        total = filteredQuery.Count(),
                        success = true,
                    }
                });
            }
        }
        public JsonResult ListFree(PublicationInstanceListArgs args)
        {
            using (var dbc = new KuLibDbContext())
            {
                var filteredQuery = dbc.PublicationInstances
                                    .Where(x => x.Publication.Id == args.PublicationId && x.RentingUser == null);
                var data = filteredQuery
                           .OrderBy(x => x.Id)
                           .Page(args)
                           .Select(x => new { Id = x.Id })
                           .ToArray();

                return(Json(new
                {
                    success = true,
                    data = data,
                    total = filteredQuery.Count(),
                }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #19
0
 protected override DbSet <JournalIssue> GetSet(KuLibDbContext dbc)
 {
     return(dbc.JournalIssues);
 }
Beispiel #20
0
 protected abstract DbSet <TEntity> GetSet(KuLibDbContext dbc);
Beispiel #21
0
 protected override DbSet <Book> GetSet(KuLibDbContext dbc)
 {
     return(dbc.Books);
 }