public async Task <IActionResult> Create([FromBody] ManagerViewModel body)
        {
            try
            {
                var entity = await _unitOfWork.Managers.GetAsync(u => u.Id == body.Id);

                if (entity != null)
                {
                    return(Payloader.Fail(PayloadCode.Duplication));
                }

                var newEntity = new Manager
                {
                    Id       = body.Id,
                    Password = body.Password,
                };

                await _unitOfWork.Managers.AddAsync(newEntity);

                await _unitOfWork.CommitAsync();

                return(Payloader.Success(_mapper.Map <ManagerViewModel>(newEntity)));
            }
            catch (Exception ex)
            {
                return(Payloader.Error(ex));
            }
        }
Example #2
0
        public async Task <IActionResult> Create([FromBody] CreateUserBody body)
        {
            try
            {
                var entity = await _unitOfWork.Users.GetAsync(x => x.Id == body.Id);

                if (entity != null)
                {
                    return(Payloader.Fail(PayloadCode.Duplication));
                }

                var newEntity = new User
                {
                    Id    = body.Id,
                    Name  = body.Name,
                    Money = 1000,
                };

                await UpdateCube(newEntity);

                await _unitOfWork.Users.AddAsync(newEntity);

                await _unitOfWork.CommitAsync();

                return(Payloader.Success(_mapper.Map <UserViewModel>(newEntity)));
            }
            catch (Exception ex)
            {
                return(Payloader.Error(ex));
            }
        }
        public async Task <IActionResult> Create([FromBody] VideoViewModel body)
        {
            try
            {
                var entity = await _unitOfWork.Videos.GetAsync(u => u.Id == body.Id);

                if (entity != null)
                {
                    return(Payloader.Fail(PayloadCode.Duplication));
                }

                var newEntity = new Video
                {
                    Title = body.Title,
                    Uri   = body.Uri,
                };

                await _unitOfWork.Videos.AddAsync(newEntity);

                await _unitOfWork.CommitAsync();

                return(Payloader.Success(_mapper.Map <VideoViewModel>(newEntity)));
            }
            catch (Exception ex)
            {
                return(Payloader.Error(ex));
            }
        }
Example #4
0
        public async Task <IActionResult> ParsingCubeData(IFormFile xml = null)
        {
            try
            {
                var datas = XmlKey.CubeData.FindAll <CubeDataXml.Data>(xml, new CubeDataXml());

                await _unitOfWork.CubeDatas.DeleteManyAsync();

                await _unitOfWork.CubeDatas.AddAsync(_mapper.Map <IEnumerable <CubeData> >(datas));

                await _unitOfWork.CommitAsync();

                return(Payloader.Success(datas.Count));
            }
            catch (Exception ex)
            {
                return(Payloader.Error(ex));
            }
        }
Example #5
0
        public async Task <IActionResult> UpdateLv(string userId, int cubeId)
        {
            try
            {
                var user = await _unitOfWork.Users.GetAsync(x => x.Id == userId, isTracking : true);

                if (user == null)
                {
                    return(Payloader.Fail(PayloadCode.DbNull));
                }

                var lv   = 0;
                var cube = await _unitOfWork.Cubes.GetAsync(x => x.UserId == userId && x.CubeId == cubeId);

                if (cube != null)
                {
                    lv = cube.Lv;
                }

                var price = ServerDefine.CubeLv2Price((byte)lv);

                if (user.Money < price)
                {
                    return(Payloader.Fail(PayloadCode.Not));
                }

                user.Money -= price;

                var newCube = await _unitOfWork.Cubes.UpdateLv(userId, cubeId, 1);

                await _unitOfWork.CommitAsync();

                return(Payloader.Success(new UpdateCubeLvBody()
                {
                    Cube = _mapper.Map <CubeViewModel>(newCube),
                    Money = user.Money,
                }));
            }
            catch (Exception ex)
            {
                return(Payloader.Error(ex));
            }
        }
Example #6
0
        public async Task <IActionResult> Update(string userId, [FromBody] int[] slots)
        {
            try
            {
                var entity = await _unitOfWork.Entries.GetAsync(x => x.UserId == userId, isTracking : true);

                if (entity == null)
                {
                    return(Payloader.Fail(PayloadCode.DbNull));
                }

                entity.Slots = slots;

                await _unitOfWork.CommitAsync();

                return(Payloader.Success(slots));
            }
            catch (Exception ex)
            {
                return(Payloader.Error(ex));
            }
        }