Ejemplo n.º 1
0
        public async Task <ActionResult> Store([FromBody] PlanViewModel model)
        {
            var plan = model.MapEntity(_mapper, CurrentUserId);

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

            await ValidateAsync(plan);

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

            plan = await _plansService.CreateAsync(plan);

            return(Ok(plan.Id));
        }
Ejemplo n.º 2
0
        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());
        }