public IEnumerable<Listing> GetListings() { var domainModel = model.Offers; IList<Listing> listings = new List<Listing>(); foreach (Offer domainModelItem in domainModel) { var viewModel = new Listing(); MapListing(MappingType.OfferToListing, viewModel, domainModelItem); listings.Add(viewModel); } return listings; }
public Listing GetListing(string listingId) { var domainModel = model.Offers.Where(m => m.ID == listingId).ToList(); if (domainModel.Count>0) { var domainModelItem = domainModel.First(); var listingModel = new Listing(); MapListing(MappingType.OfferToListing, listingModel, domainModelItem); return listingModel; } return null; }
public Listing AddListing(Listing listing) { var domainModel = new Offer(); try { MapListing(MappingType.ListingToOffer, listing, domainModel); domainModel.ID = Guid.NewGuid().ToString(); model.Offers.Add(domainModel); model.SaveChanges(); listing.Id = domainModel.ID; } catch (Exception ex) { throw ex; } return listing; }
public bool UpdateListing(Listing listing) { throw new NotImplementedException(); }
private void MapListing(MappingType typeOfMapping, Listing viewModel, Offer domainModel) { if (typeOfMapping == MappingType.ListingToOffer) { if (viewModel != null) { //domainModel. viewModel.DateCreated; domainModel.ID = viewModel.Id; domainModel.Title = viewModel.Title; var userObject = GetOrCreateUser(viewModel.UserEmail,viewModel.UserName,viewModel.Location,""); domainModel.UserID = userObject.ID; domainModel.Status = Convert.ToInt16(viewModel.Status); var categoryObject = GetOrCreateCategory(viewModel.CategoryName); if (categoryObject != null) { domainModel.CategoryID = categoryObject.ID; } domainModel.CreatedDateTime = viewModel.DateCreated; domainModel.ModifiedDate = viewModel.DateModified; domainModel.Photo = viewModel.Photo; domainModel.Description = viewModel.Description; } } else { viewModel.Id = domainModel.ID; viewModel.Title = domainModel.Title; viewModel.Status = (ListingStatus)domainModel.Status; viewModel.Type = ListingType.Offered; viewModel.DateModified = domainModel.ModifiedDate; viewModel.DateCreated = domainModel.CreatedDateTime; viewModel.Description = domainModel.Description; viewModel.UserEmail = domainModel.User.Email; viewModel.UserName = domainModel.User.Name; viewModel.Location = domainModel.User.Location; viewModel.Photo = domainModel.Photo; } }