public DefaultResponse SaveDrinkList(DrinkRequest.ImportDrinkList request) { try { if (request.Drinks != null && request.Drinks.Any()) { foreach (var drink in request.Drinks) { try { _drinkService.Create(drink.Caption, drink.Image, drink.Cost, drink.Count); } catch { // ignored } } } return(new DefaultResponse { Message = string.Empty, ErrorCode = 0 }); } catch (Exception e) { return(new DefaultResponse { Message = e.Message, ErrorCode = 2 }); } }
public HttpResponseMessage Post(DrinkCreate drinkCreateData) { var drink = new Drink() { Name = drinkCreateData.Name, Quantity = drinkCreateData.Quantity }; var validationResult = _drinkValidator.Validate(drink); try { if (validationResult.IsValid) { var drinkResult = _drinkService.Create(drink); return(Request.CreateResponse <Drink>(HttpStatusCode.OK, drinkResult)); } else { var responseError = new ResponseError() { Errors = validationResult.ErrorList }; return(Request.CreateResponse <ResponseError>(HttpStatusCode.BadRequest, responseError)); } } catch (ArgumentException ex) { var responseError = new ResponseError() { Errors = new List <string>() { ex.Message } }; return(Request.CreateResponse <ResponseError>(HttpStatusCode.BadRequest, responseError)); } }