Ejemplo n.º 1
0
        public async Task <ActionResult> Edit(ServingEditDtoModel request)
        {
            if (!ModelState.IsValid)
            {
                string message = "";
                foreach (var er in ModelState.Values.SelectMany(modelstate => modelstate.Errors))
                {
                    message += er.ErrorMessage + " \n";
                }

                return(Ok(new ResultSetDto()
                {
                    IsSuced = false,
                    Message = message
                }));
            }

            ResultSetDto <ServingEditDtoModel> result = await Api.GetHandler
                                                        .GetApiAsync <ResultSetDto <ServingEditDtoModel> >(ApiAddress.EditServing, request);

            return(Json(result));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <ResultSetDto <ServingEditDtoModel> > > EditServing([FromBody] ServingEditDtoModel request)
        {
            if (!ModelState.IsValid)
            {
                string message = "";
                foreach (var er in ModelState.Values.SelectMany(modelstate => modelstate.Errors))
                {
                    message += er.ErrorMessage + " \n";
                }

                return(Ok(new ResultSetDto()
                {
                    IsSuced = false,
                    Message = message
                }));
            }



            var resultServing = await _servingService.GetServingByIdAsync(Guid.Parse(request.ServingId));

            if (!resultServing.IsSucced)
            {
                return(BadRequest(resultServing.Message));
            }

            Serving servingEdit = resultServing.Data;

            servingEdit.Title = request.Title;
            servingEdit.Price = request.Price;
            servingEdit.Desc  = request.Desc;

            var result = await _servingService.EditServingAsync(servingEdit);

            if (!result.IsSucced)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(new ResultSetDto <ServingEditDtoModel>()
            {
                IsSuced = true,
                Message = "",
                Data = request
            }));
        }