Example #1
0
        public async Task <ActionResult <TypeOfPacketDto> > DeleteTypeOfPacket(int id, string userId)
        {
            var typeOfPacket = await _context.TypeOfPackets.FindAsync(id);

            if (typeOfPacket == null)
            {
                return(NotFound());
            }
            typeOfPacket.DeletedDate           = DateTime.Now;
            typeOfPacket.DeletedUserId         = userId;
            typeOfPacket.VirtualDeleted        = true;
            _context.Entry(typeOfPacket).State = EntityState.Modified;
            var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == userId);

            var log = new Log()
            {
                DateTime     = DateTime.Now,
                TypeFullName = typeof(TypeOfPacket).FullName,
                Content      = "@userName@deleteAction@objTitle",
                TypeId       = typeOfPacket.Id,
                UserId       = user.Id
            };

            _context.Logs.Add(log);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TypeOfPacketExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            var result = new TypeOfPacketDto()
            {
                Id           = typeOfPacket.Id,
                Name         = typeOfPacket.Name,
                ForeignName  = typeOfPacket.ForeignName,
                Cost         = typeOfPacket.Cost,
                LessonsCount = typeOfPacket.LessonsCount
            };

            return(result);
        }
Example #2
0
        public async Task <ActionResult <TypeOfPacketDto> > PostTypeOfPacket(TypeOfPacketInputDto input)
        {
            try
            {
                var typeOfPacket = new TypeOfPacket()
                {
                    Name          = input.Name,
                    ForeignName   = input.ForeignName,
                    Cost          = input.Cost,
                    LessonsCount  = input.LessonsCount,
                    CreatedDate   = DateTime.Now,
                    CreatedUserId = input.UserId
                };
                _context.TypeOfPackets.Add(typeOfPacket);
                await _context.SaveChangesAsync();

                var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == input.UserId);

                var log = new Log()
                {
                    DateTime     = DateTime.Now,
                    TypeFullName = typeof(TypeOfPacket).FullName,
                    Content      = "@userName@addAction@objTitle",
                    TypeId       = typeOfPacket.Id,
                    UserId       = user.Id
                };
                _context.Logs.Add(log);
                await _context.SaveChangesAsync();

                var result = new TypeOfPacketDto()
                {
                    Id           = typeOfPacket.Id,
                    Name         = typeOfPacket.Name,
                    ForeignName  = typeOfPacket.ForeignName,
                    Cost         = typeOfPacket.Cost,
                    LessonsCount = typeOfPacket.LessonsCount
                };
                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #3
0
        public async Task <ActionResult <TypeOfPacketDto> > GetTypeOfPacket(int id)
        {
            var typeOfPacket = await _context.TypeOfPackets.FindAsync(id);

            if (typeOfPacket == null)
            {
                return(NotFound());
            }
            var result = new TypeOfPacketDto()
            {
                Id           = typeOfPacket.Id,
                Name         = typeOfPacket.Name,
                ForeignName  = typeOfPacket.ForeignName,
                Cost         = typeOfPacket.Cost,
                LessonsCount = typeOfPacket.LessonsCount
            };

            return(result);
        }