public void AddAdvert(DataTransferObjects.Advert advert, string userName) { try { var mapper = new MapperConfiguration(c => c.CreateMap <DataTransferObjects.Advert, DAL.Model.Advert>()).CreateMapper(); var mappedRes = mapper.Map <DataTransferObjects.Advert, DAL.Model.Advert>(advert); mappedRes.Created = DateTime.Now; mappedRes.UserId = GetUserId(userName); data.Advert.Create(mappedRes); data.Save(); } catch (Exception ex) { throw ex; } }
public bool EditAdvert(DataTransferObjects.Advert advert) { //var mapper = new MapperConfiguration(c => c.CreateMap<DataTransferObjects.Advert, DAL.Model.Advert>()).CreateMapper(); //var mappedRes = mapper.Map<DataTransferObjects.Advert, DAL.Model.Advert>(advert); var old = data.Advert.Get(advert.Id); old.Body = advert.Body; old.Category = advert.Category; old.New = advert.New; old.Price = advert.Price; old.Title = advert.Title; if (advert.Photo.Length > 0) { old.Photo = advert.Photo; } old.LastUpdate = DateTime.Now; data.Advert.Update(old); data.Save(); return(true); }