示例#1
0
        public async Task <ActionResult> PatchPromotionProductAsync(int id, [FromBody] JsonPatchDocument <PromotionProduct> patch)
        {
            var promotionProduct = await _promotionContext.FindAsync <PromotionProduct>(id);

            if (promotionProduct == null)
            {
                return(NotFound());
            }

            try
            {
                patch.ApplyTo(promotionProduct);
                _promotionContext.Update(promotionProduct);
                await _promotionContext.SaveChangesAsync();

                _logger.LogInformation("PatchPromotionProductAsync Success {@promotionProduct}.", promotionProduct);
            }
            catch (Exception)
            {
                _logger.LogError("PatchPromotionProductAsync Failed {@patch}---{@promotionProduct}", patch, promotionProduct);
                return(StatusCode(500, "Paching Failed "));
            }


            return(CreatedAtAction(nameof(ItemByIdAsync), new { id = promotionProduct.Id }, null));
        }
示例#2
0
        public async Task SaveAct(ActInfo actModel)
        {
            var act = await repository.GetOrInsertAct(actModel.ActGuid);

            var lastActDescription = act.Descriptions
                                     .OrderByDescending(description => description.ModifiedDate)
                                     .FirstOrDefault();

            if (lastActDescription == null ||
                lastActDescription.Title != actModel.Title ||
                lastActDescription.ImageHash != actModel.ImageHash)
            {
                var modifiedTicks = lastActDescription?.ModifiedDate.Ticks ?? 0;
                if (modifiedTicks != actModel.LastModifiedTicks)
                {
                    throw new DbUpdateConcurrencyException("A new update has occurred since you loaded the page. Please refresh and try again.");
                }

                await repository.AddAsync(new ActDescription
                {
                    ModifiedDate = DateTime.UtcNow,
                    Act          = act,
                    Title        = actModel.Title,
                    ImageHash    = actModel.ImageHash
                });

                await repository.SaveChangesAsync();
            }
        }
        public async Task <IActionResult> Create(
            [Bind("Title,Description,PromotionTypeId,StartDate, EndDate,PromotionProductTypeId")] PromotionDto promotionDto)
        {
            promotionDto.PromotionState = PromotionState.Created;
            var flag = false;

            if (ModelState.IsValid)
            {
                if (promotionDto.EndDate <= promotionDto.StartDate ||
                    promotionDto.EndDate <= DateTime.Now)
                {
                    ModelState.AddModelError("EndDate", "结束时间不能小于开始时间或当前系统时间");
                }
                else
                {
                    flag = true;
                }
            }
            if (flag)
            {
                var promotion = _mapper.Map <Promotion>(promotionDto);
                _promotionContext.Promotions.Add(promotion);
                await _promotionContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["PromotionTypes"] = GeneratePromotionTypes();
            //ViewData["PromotionStates"] = GeneratePromotionStates();
            ViewData["PromotionProductTypes"] = GeneratePromotionProductTypes();
            return(View(promotionDto));
        }
        public async Task DeleteVenue(Guid venueGuid)
        {
            var venue = await repository.GetOrInsertVenue(venueGuid);

            await repository.AddAsync(new VenueRemoved
            {
                Venue       = venue,
                RemovedDate = DateTime.UtcNow
            });

            await repository.SaveChangesAsync();
        }
        public async Task <string> SaveContent(byte[] binary, string contentType)
        {
            var sha512 = HashAlgorithm.Create(HashAlgorithmName.SHA512.Name);
            var hash   = Convert.ToBase64String(sha512.ComputeHash(binary));

            // avoid any slashes, plus signs or equal signs
            // the following makes this base64 string url safe
            hash = hash.Replace("/", "_");
            hash = hash.Replace("+", "-");

            var exists = await repository.Content
                         .Where(c => c.Hash == hash)
                         .AnyAsync();

            if (!exists)
            {
                await repository.Content.AddAsync(new Content
                {
                    Hash        = hash,
                    Binary      = binary,
                    ContentType = contentType
                });

                await repository.SaveChangesAsync();
            }

            return(hash);
        }
示例#6
0
        public async Task ScheduleShow(Guid actGuid, Guid venueGuid, DateTimeOffset startTime)
        {
            await repository.GetOrInsertShow(actGuid, venueGuid, startTime);

            await repository.SaveChangesAsync();
        }