public async Task <IActionResult> Post([FromForm] CreateMobilePhoneRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var mobilePhone = await _mobilePhoneService.CreateMobilePhoneAsync(createRequest);

            var path = String.Format("/api/phones/{0}", mobilePhone.Id);

            return(Created(path, mobilePhone));
        }
Exemple #2
0
        /// <inheritdoc/>
        public async Task <MobilePhone> CreateMobilePhoneAsync(CreateMobilePhoneRequest createRequest)
        {
            var mobilePhones = Mapper.Map <List <MobilePhone> >(_repository.MobilePhones);
            int id           = mobilePhones.Count == 0 ? 1 : mobilePhones.Max(ph => ph.Id) + 1;

            var mobilePhone = new MobilePhone
            {
                Id        = id,
                Name      = createRequest.Name,
                PhotoPath = await _imageService.SaveImage(createRequest.PhotoFile)
            };

            mobilePhones.Add(mobilePhone);
            _repository.Save(Mapper.Map <List <DataAccess.MobilePhone> >(mobilePhones));
            return(mobilePhone);
        }