Esempio n. 1
0
        public IHttpActionResult UpdateGift(int id, GiftEditDto giftEditDto)
        {
            if (!ModelState.IsValid || giftEditDto == null)
            {
                return(BadRequest());
            }

            var gift = Context.Gifts.FirstOrDefault(x => x.Id == id);

            if (gift == null || gift.UserId != User.Identity.GetUserId())
            {
                return(NotFound());
            }

            if (gift.Status == GiftStatus.Donated)
            {
                return(BadRequest("Can't edit after donation."));
            }

            gift.Title       = giftEditDto.Title;
            gift.Address     = giftEditDto.Address;
            gift.Description = giftEditDto.Description;
            gift.Price       = giftEditDto.Price;
            gift.CategoryId  = giftEditDto.CategoryId;
            gift.CityId      = giftEditDto.CityId;
            gift.RegionId    = giftEditDto.RegionId;

            var giftImages = Context.GiftImages.Where(x => x.GiftId == gift.Id).ToList();

            Context.GiftImages.RemoveRange(giftImages);
            Context.SaveChanges();

            foreach (var giftImageDto in giftEditDto.GiftImages)
            {
                var giftImage = new GiftImage
                {
                    GiftId   = gift.Id,
                    ImageUrl = giftImageDto,
                    UserId   = gift.UserId
                };

                Context.GiftImages.Add(giftImage);
            }

            Context.SaveChanges();

            return(Ok());
        }
Esempio n. 2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ActivityId != 0)
            {
                hash ^= ActivityId.GetHashCode();
            }
            if (MallId != 0)
            {
                hash ^= MallId.GetHashCode();
            }
            if (MallItemId != 0)
            {
                hash ^= MallItemId.GetHashCode();
            }
            if (MallName.Length != 0)
            {
                hash ^= MallName.GetHashCode();
            }
            if (MallDesc.Length != 0)
            {
                hash ^= MallDesc.GetHashCode();
            }
            if (GiftImage.Length != 0)
            {
                hash ^= GiftImage.GetHashCode();
            }
            if (LabelImage.Length != 0)
            {
                hash ^= LabelImage.GetHashCode();
            }
            if (Price != 0)
            {
                hash ^= Price.GetHashCode();
            }
            if (BuyMax != 0)
            {
                hash ^= BuyMax.GetHashCode();
            }
            hash ^= awards_.GetHashCode();
            return(hash);
        }
Esempio n. 3
0
        public IHttpActionResult CreateGift(GiftAddDto giftAddDto)
        {
            if (!ModelState.IsValid || giftAddDto == null)
            {
                return(BadRequest());
            }

            var gift = new Gift
            {
                Title       = giftAddDto.Title,
                Address     = giftAddDto.Address,
                Description = giftAddDto.Description,
                Price       = giftAddDto.Price,
                CategoryId  = giftAddDto.CategoryId,
                CityId      = giftAddDto.CityId,
                RegionId    = giftAddDto.RegionId,
                Status      = GiftStatus.WaitingToBeDonated,
                UserId      = User.Identity.GetUserId()
            };


            Context.Gifts.Add(gift);
            Context.SaveChanges();

            foreach (var giftImageDto in giftAddDto.GiftImages)
            {
                var giftImage = new GiftImage
                {
                    GiftId   = gift.Id,
                    ImageUrl = giftImageDto,
                    UserId   = gift.UserId
                };

                Context.GiftImages.Add(giftImage);
            }


            Context.SaveChanges();

            var giftItemDtop = Mapper.Map <Gift, GiftPrivateItemDto>(gift);

            return(Created(new Uri(Request.RequestUri + "/" + gift.Id), giftItemDtop));
        }
Esempio n. 4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (MallId != 0)
            {
                hash ^= MallId.GetHashCode();
            }
            if (CommodityType != 0)
            {
                hash ^= CommodityType.GetHashCode();
            }
            if (MallSort != 0)
            {
                hash ^= MallSort.GetHashCode();
            }
            if (MallName.Length != 0)
            {
                hash ^= MallName.GetHashCode();
            }
            if (MallDesc.Length != 0)
            {
                hash ^= MallDesc.GetHashCode();
            }
            if (GiftImage.Length != 0)
            {
                hash ^= GiftImage.GetHashCode();
            }
            if (Slot != 0)
            {
                hash ^= Slot.GetHashCode();
            }
            if (MallLabel != 0)
            {
                hash ^= MallLabel.GetHashCode();
            }
            if (LabelImage.Length != 0)
            {
                hash ^= LabelImage.GetHashCode();
            }
            if (RealPrice != 0)
            {
                hash ^= RealPrice.GetHashCode();
            }
            if (OriginalPrice != 0)
            {
                hash ^= OriginalPrice.GetHashCode();
            }
            if (BuyMax != 0)
            {
                hash ^= BuyMax.GetHashCode();
            }
            if (BuyRefreshDay != 0)
            {
                hash ^= BuyRefreshDay.GetHashCode();
            }
            hash ^= award_.GetHashCode();
            if (StartTime != 0L)
            {
                hash ^= StartTime.GetHashCode();
            }
            if (EndTime != 0L)
            {
                hash ^= EndTime.GetHashCode();
            }
            if (Special != false)
            {
                hash ^= Special.GetHashCode();
            }
            return(hash);
        }