Пример #1
0
        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;
        }
Пример #2
0
        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;
            }
        }