コード例 #1
0
        public static MarketNotificationDto ToMarketNotificationDto(this MarketNotification marketNotification)
        {
            if (marketNotification != null)
            {
                return(new MarketNotificationDto
                {
                    Id = marketNotification.Id,
                    Price = marketNotification.Price,
                    PriceType = marketNotification.PriceType.ToMarketNotificationTypeDto(),
                    Quantity = marketNotification.Quantity,
                    QuantityType = marketNotification.QuantityType.ToMarketNotificationTypeDto(),
                    Item = marketNotification.Item.ToItemDto(),
                    Realm = marketNotification.Realm.ToRealmDto(),
                    ActionState = eActionState.None
                });
            }

            return(null);
        }
コード例 #2
0
        public async Task <ActionResult <MarketNotificationDto> > SaveMarketNotification([FromBody] MarketNotificationDto dto)
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            var result = dto;

            if (user == null)
            {
                return(Unauthorized(result));
            }

            if (dto.ActionState == eActionState.Insert)
            {
                var marketNotification = new MarketNotification
                {
                    Id             = Guid.NewGuid(),
                    ItemId         = dto.Item.Id,
                    PriceTypeId    = dto.PriceType != null ? (int?)dto.PriceType.Id : null,
                    Price          = dto.Price,
                    Quantity       = dto.Quantity,
                    QuantityTypeId = dto.QuantityType != null ? (int?)dto.QuantityType.Id : null,
                    RealmId        = dto.Realm.Id,
                    UserId         = user.Id,
                };
                await _unitOfWork.MarketNotificationRepository.InsertAsync(marketNotification);

                await _unitOfWork.SaveAsync();

                result.Id = marketNotification.Id;
            }
            else if (dto.ActionState == eActionState.Update)
            {
                var marketNotification = await _unitOfWork.MarketNotificationRepository.GetByIDAsync(dto.Id);

                if (marketNotification == null || marketNotification.UserId != user.Id)
                {
                    return(Unauthorized(result));
                }

                marketNotification.ItemId         = dto.Item.Id;
                marketNotification.PriceTypeId    = dto.PriceType != null ? (int?)dto.PriceType.Id : null;
                marketNotification.Price          = dto.Price;
                marketNotification.Quantity       = dto.Quantity;
                marketNotification.QuantityTypeId = dto.QuantityType != null ? (int?)dto.QuantityType.Id : null;
                marketNotification.RealmId        = dto.Realm.Id;

                await _unitOfWork.MarketNotificationRepository.UpdateAsync(marketNotification);

                await _unitOfWork.SaveAsync();
            }
            else if (dto.ActionState == eActionState.Delete)
            {
                var marketNotification = await _unitOfWork.MarketNotificationRepository.GetByIDAsync(dto.Id);

                if (marketNotification == null || marketNotification.UserId != user.Id)
                {
                    return(Unauthorized(result));
                }

                await _unitOfWork.MarketNotificationRepository.DeleteAsync(dto.Id);

                await _unitOfWork.SaveAsync();
            }
            else
            {
                return(BadRequest(false));
            }

            result.ActionState = eActionState.None;
            return(Ok(result));
        }