Esempio n. 1
0
        public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] PlanResource planResource)
        {
            if (planResource == null)
            {
                planResource = new PlanResource();
            }

            var plan   = _mapper.Map <PlanResource, Plan>(planResource);
            var result = await _plansService.UpdateAsync(id, plan);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
        public async Task <ActionResult> Update(int id, [FromBody] PlanViewModel model)
        {
            var existingEntity = await _plansService.GetByIdAsync(id);

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

            var plan = model.MapEntity(_mapper, CurrentUserId);

            plan.Discount = 50;               //固定五折

            await ValidateAsync(plan);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _plansService.UpdateAsync(existingEntity, plan);

            return(Ok());
        }