public async Task <BaseResponse> Post([FromBody] MobileViewModel model) { InsertMobileModel insertModel = new InsertMobileModel { Brand = model.Brand, CPU = model.CPU, InternalMemory = model.InternalMemory, Name = model.Name, OS = model.OS, Price = model.Price, RAM = model.RAM, ScreenResolution = model.ScreenResolution, ScreenSize = model.ScreenSize, Size = model.Size, VideoUrl = model.VideoUrl, Weight = model.Weight }; foreach (var item in model.Photos) { Domain.DTO.ServiceModels.Photo photo = new Domain.DTO.ServiceModels.Photo { Base64 = item.Base64, PhotoId = item.PhotoId }; insertModel.Photos.Add(photo); } return(await _mobileService.InsertMobile(insertModel)); }
public async Task <BaseResponse> InsertMobile(InsertMobileModel model) { BaseResponse response = null; try { var repo = (_mobilieRepository as MobileRepository); response = BaseResponse.Ok(); var mobile = new Mobile { Brand = model.Brand, CPU = model.CPU, InternalMemory = model.InternalMemory, Name = model.Name, OS = model.OS, Price = model.Price, RAM = model.RAM, ScreenResolution = model.ScreenResolution, ScreenSize = model.ScreenSize, Size = model.Size, VideoUrl = model.VideoUrl, Weight = model.Weight }; foreach (var item in model.Photos) { var photo = new Domain.DAO.Entities.Photo() { Value = item.Base64 }; mobile.Photos.Add(photo); } repo.Add(mobile); repo.Save(); } catch (Exception ex) { _logger.LogError(ex.Message); response = BaseResponse.Fail($"Could not add item"); } return(response); }