Ejemplo n.º 1
0
        public IActionResult EditListing(int id)
        {
            var listing = listingRepo.GetListing(id);
            EditListingViewModel model = new EditListingViewModel()
            {
                Id                = listing.Id,
                Title             = listing.Title,
                Address           = listing.Address,
                City              = listing.City,
                State             = listing.State,
                ZipCode           = listing.ZipCode,
                Description       = listing.Description,
                Price             = listing.Price,
                Bedrooms          = listing.Bedrooms,
                Bathrooms         = listing.Bathrooms,
                Garage            = listing.Garage,
                Sqft              = listing.Sqft,
                LotSize           = listing.LotSize,
                IsPublished       = listing.IsPublished,
                RealtorId         = listing.RealtorId,
                Realtors          = realtorRepo.GetRealtors(),
                ExistingPhotoMain = listing.PhotoMain,
                ExistingPhoto1    = listing.Photo1,
                ExistingPhoto2    = listing.Photo2,
                ExistingPhoto3    = listing.Photo3,
                ExistingPhoto4    = listing.Photo4,
                ExistingPhoto5    = listing.Photo5,
                ExistingPhoto6    = listing.Photo6,
            };

            return(View(model));
        }
        public ActionResult AddListing(EditListingViewModel model)
        {
            if (!_orchardServices.Authorizer.Authorize(Permissions.ivOwnerTab, T("You are not authorized")))
                Response.Redirect("/Users/Account/AccessDenied?ReturnUrl=/");

            var ownerKey = CustomStringHelper.BuildKey(new[] { CurrentUser.Email });
            if(_orchardServices.Authorizer.Authorize(Permissions.ivAdminTab))
            {
                ownerKey = CustomStringHelper.BuildKey(new[] { model.Email });
            }

            var ownerId = _ownerServices.GetOwnerIdByKey(ownerKey);
       
            _ownerServices.AddListing(ownerId, model);
            var package = "Free";
            switch (model.Package)
            {
                case "2":
                    package = "Full";
                    break;
                case "3":
                    package = "Featured";
                    break;
            }

            _emailServices.SendNotificationEmail(package, CurrentUser.Email);

            string returnUrl = "/owner/my-listings";
            if (_orchardServices.Authorizer.Authorize(Permissions.ivAdminTab))
            {
                returnUrl = "/admin/listings";
            }
            
            return Redirect(returnUrl);
        }
Ejemplo n.º 3
0
        public ActionResult Listing(int bookId)
        {
            EditListingViewModel viewModel = new EditListingViewModel();

            viewModel.book    = ctx.Books.Where(a => a.ID == bookId).FirstOrDefault();
            viewModel.courses = ctx.Courses.ToList();

            return(View("Listing", viewModel));
        }
Ejemplo n.º 4
0
        public ActionResult DeleteListing(EditListingViewModel viewModel)
        {
            var temp = ctx.BookListings.Where(a => a.ID == viewModel.ID && a.Status == 0).FirstOrDefault();

            ctx.BookListings.Remove(temp);
            ctx.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public ActionResult EditListing(int id)
        {
            var viewModel = new EditListingViewModel();
            var temp      = ctx.BookListings.Include("Book").Include("Course").Where(a => a.ID == id && a.Status == 0).FirstOrDefault();

            viewModel.ID        = id;
            viewModel.book      = temp.Book;
            viewModel.course    = temp.Course;
            viewModel.condition = temp.Condition;
            viewModel.price     = temp.AskingPrice;
            return(View("EditListing", viewModel));
        }
Ejemplo n.º 6
0
        public ActionResult EditListing(EditListingViewModel model)
        {
            CoreysListEntities db = new CoreysListEntities();

            try
            {
                // if the listing ID is -1 then it is a new listing
                if (model.Listing.ListingID == -1)
                {
                    // add new listing
                    Listing listing = new Listing();
                    listing.CityID        = model.Listing.CityID;
                    listing.UserID        = Convert.ToInt32(Session["UserId"]);
                    listing.SubCategoryID = model.Listing.SubCategoryID;
                    listing.Headline      = model.Listing.Headline;
                    listing.Location      = model.Listing.Location;
                    listing.Description   = model.Listing.Description;
                    listing.Price         = model.Listing.Price;
                    listing.CreatedBy     = "corey";
                    listing.CreatedDate   = DateTime.Now;

                    db.Listings.Add(listing);
                    db.SaveChanges();
                }
                else
                {
                    // get the listing being edited
                    Listing listing = db.Listings.FirstOrDefault(l => l.ListingID == model.Listing.ListingID);

                    // update all the fields and save
                    listing.CityID        = model.Listing.CityID;
                    listing.UserID        = Convert.ToInt32(Session["UserId"]);
                    listing.SubCategoryID = model.Listing.SubCategoryID;
                    listing.Headline      = model.Listing.Headline;
                    listing.Location      = model.Listing.Location;
                    listing.Description   = model.Listing.Description;
                    listing.Price         = model.Listing.Price;
                    listing.ModifiedBy    = listing.User.Email;
                    listing.ModifiedDate  = DateTime.Now;

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            // return success and handle navigation in jquery
            return(Json(new { Success = true }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Listing(EditListingViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = await usrCtx.GetUserAsync(HttpContext.User);

                BookListing newListing = new BookListing();
                newListing.ApplicationUserID = user.Id;
                if (Request.Form["listingTradeCheckBox"] == "on")
                {
                    newListing.AskingPrice = -1;
                }
                else
                {
                    newListing.AskingPrice = viewModel.price;
                }

                newListing.Condition = viewModel.condition;
                newListing.BookID    = viewModel.book.ID;
                newListing.Type      = SELL;
                if (!viewModel.newCourse)// if they picked a course from the dropdown
                {
                    newListing.CourseID = viewModel.courseID;
                }
                else // if they created a new course
                {
                    Course newCourse = new Course();
                    newCourse.Dept      = viewModel.courseDept;
                    newCourse.CourseNum = Int16.Parse(viewModel.courseNum);
                    newCourse.Name      = viewModel.courseName;
                    newCourse.SchoolID  = user.SchoolID;
                    //newCourse.BookToCourses.Add();
                    ctx.Courses.Add(newCourse);
                    newListing.Course = newCourse;
                }

                ctx.BookListings.Add(newListing);
                ctx.SaveChanges();

                return(RedirectToAction("Index", "Profile"));
            }
            else
            {
                viewModel.book    = ctx.Books.Where(a => a.ID == viewModel.book.ID).FirstOrDefault();
                viewModel.courses = ctx.Courses.ToList();
                return(View(viewModel));
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> EditListing(EditListingViewModel viewModel)
        {
            var temp = ctx.BookListings.Where(a => a.ID == viewModel.ID && a.Status == 0).FirstOrDefault();
            // Find all open transactions and remove them
            var openLogs = ctx.TransactionLogs.Where(a => a.SellerID == temp.ApplicationUserID && a.BookID == temp.BookID && a.Condition == temp.Condition && a.SoldPrice == temp.AskingPrice);

            foreach (TransactionLog log in openLogs)
            {
                ctx.TransactionLogs.Remove(log);
            }

            Course newCourse = new Course();

            temp.Condition   = viewModel.condition;
            temp.CourseID    = viewModel.courseID;
            temp.AskingPrice = viewModel.price;
            // If they created a new course, add the course to the database.
            if (viewModel.newCourse)
            {
                newCourse.Dept      = viewModel.courseDept;
                newCourse.CourseNum = viewModel.courseID;
                newCourse.Name      = viewModel.courseName;
                ApplicationUser user = await usrCtx.GetUserAsync(HttpContext.User);

                newCourse.SchoolID = user.SchoolID;
                ctx.Courses.Add(newCourse);
                temp.Course = newCourse;
            }

            ctx.Update(temp);
            ctx.SaveChanges();

            // Put it after the new course is added and saved into the database so it receives an ID.
            if (viewModel.newCourse)
            {
                // Connect the book and the new course if it doesn't already exist.
                if (!ctx.BookToCourses.Where(a => a.BookID == viewModel.book.ID && a.CourseID == newCourse.ID).Any())
                {
                    BookToCourse bookToCourse = new BookToCourse();
                    bookToCourse.BookID   = viewModel.book.ID;
                    bookToCourse.CourseID = newCourse.ID;
                    ctx.BookToCourses.Add(bookToCourse);
                    ctx.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 9
0
        public ActionResult EditListing(EditListingViewModel viewModel)
        {
            var temp = ctx.BookListings.Where(a => a.ID == viewModel.ID && a.Status == 0).FirstOrDefault();

            temp.Condition = viewModel.condition;
            if (Request.Form["editTradeCheckBox"] == "on")
            {
                temp.AskingPrice = -1;
            }
            else
            {
                temp.AskingPrice = viewModel.price;
            }

            ctx.Update(temp);
            var success = ctx.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 10
0
        public ActionResult DeleteListing(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var viewModel = new EditListingViewModel();
            var temp      = ctx.BookListings.Include("Book").Include("Course").Where(a => a.ID == id && a.Status == 0).FirstOrDefault();

            if (temp == null)
            {
                return(NotFound());
            }
            viewModel.ID        = temp.ID;
            viewModel.book      = temp.Book;
            viewModel.course    = temp.Course;
            viewModel.condition = temp.Condition;
            viewModel.price     = temp.AskingPrice;
            return(View("DeleteListing", viewModel));
        }
        public HttpResponseMessage Get()
        {
            var errorList = new List<string>();

            var siteDataXml = new XmlDocument();

            siteDataXml.Load(HttpContext.Current.Server.MapPath("~/Modules/ivNet.Listing/App_Data/SiteData.xml"));

            //siteDataXml.Load(HttpContext.Current.Server.MapPath("~/Modules/ivNet.Listing/App_Data/TestData.xml"));

            if (siteDataXml.DocumentElement != null)
            {
                foreach (XmlNode listing in siteDataXml.DocumentElement.SelectNodes("listing"))
                {
                    // create category
                    var categoryId = 0;
                    var categoryName = listing.SelectSingleNode("category") == null
                        ? "unknown"
                        : listing.SelectSingleNode("category").InnerText;
                    try
                    {
                        categoryId = _configurationServices.CreateCategory(categoryName).Id;
                    }
                    catch (Exception ex)
                    {
                        errorList.Add(getErrorMessage("category", categoryName, ex));
                    }

                    var name = listing.SelectSingleNode("key[@name]") == null
                        ? string.Empty
                        : listing.SelectSingleNode("key[@name]").InnerText;

                    var nameParts = name.Split(' ');

                    var pw = CustomStringHelper.GenerateInitialPassword(new Owner {Firstname = nameParts[0]});

                    // create owner
                    var registrationModel = new RegistrationViewModel
                    {
                        Firstname = nameParts[0],

                        Surname = nameParts.Length == 1
                            ? "unknown"
                            : nameParts[1],

                        Email = listing.SelectSingleNode("post_content") == null
                            ? "*****@*****.**"
                            : listing.SelectSingleNode("email").InnerXml,

                        Address1 = listing.SelectSingleNode("map_location") == null
                            ? string.Empty
                            : listing.SelectSingleNode("map_location").InnerText,

                        Town = listing.SelectSingleNode("key[@town]") == null
                            ? string.Empty
                            : listing.SelectSingleNode("key[@town]").InnerText,

                        Postcode = listing.SelectSingleNode("key[@postcode]") == null
                            ? string.Empty
                            : listing.SelectSingleNode("key[@postcode]").InnerText,

                        Phone = listing.SelectSingleNode("key[@telephone]") == null
                            ? string.Empty
                            : listing.SelectSingleNode("key[@telephone]").InnerText,

                        Website = listing.SelectSingleNode("key[@url]") == null
                            ? string.Empty
                            : listing.SelectSingleNode("key[@url]").InnerText,

                        Password = pw,
                        ConfirmPassword = pw
                    };

                    // try and sort out address
                    var addressParts = registrationModel.Address1.Split(',');
                    if (addressParts.Length > 1)
                    {
                        registrationModel.Address1 = addressParts[0];
                        for (var i = 1; i < addressParts.Length; i++)
                        {
                            registrationModel.Address2 = string.Format("{0} {1}", registrationModel.Address2,
                                addressParts[i]).Trim();
                        }
                    }

                    try
                    {
                        _registrationServices.UpdateOwner(registrationModel);
                        var user = _registrationServices.CreateOwnerUser(
                            new ActivationViewModel
                            {
                                ConfirmPassword = registrationModel.ConfirmPassword,
                                Email = registrationModel.Email,
                                Password = registrationModel.Password,
                                Message = ""
                            });
                        _registrationServices.UpdateOwnerUserId(user.Email, user.Id);
                    }
                    catch (Exception ex)
                    {
                        errorList.Add(getErrorMessage("owner", registrationModel.Email, ex));
                    }

                    // create listing
                    var description = listing.SelectSingleNode("post_content") == null
                        ? string.Empty
                        : listing.SelectSingleNode("post_content").InnerXml;

                    var strapLine = listing.SelectSingleNode("post_content") == null
                        ? string.Empty
                        : listing.SelectSingleNode("post_title").InnerXml;

                    // mop up some data just for admin view
                    var notes = string.Format("[Featured]:{0} - [Hits]:{1} - [Key 3]:{2} - [Key 4]:{3} - [Key 5]:{4} - [Package Access]:{5} - [Tagline]{6}",
                       listing.SelectSingleNode("featured") == null
                        ? string.Empty
                        : listing.SelectSingleNode("featured").InnerXml,
                        listing.SelectSingleNode("hits") == null
                        ? string.Empty
                        : listing.SelectSingleNode("hits").InnerXml,
                         listing.SelectSingleNode("key_3") == null
                        ? string.Empty
                        : listing.SelectSingleNode("key_3").InnerXml,
                         listing.SelectSingleNode("key_4") == null
                        ? string.Empty
                        : listing.SelectSingleNode("key_4").InnerXml,
                         listing.SelectSingleNode("key_5") == null
                        ? string.Empty
                        : listing.SelectSingleNode("key_5").InnerXml,
                         listing.SelectSingleNode("package_access") == null
                        ? string.Empty
                        : listing.SelectSingleNode("package_access").InnerXml,
                        listing.SelectSingleNode("tagline") == null
                        ? string.Empty
                        : listing.SelectSingleNode("tagline").InnerXml
                        
                        );

                    var listingModel = new EditListingViewModel
                    {
                        StrapLine = strapLine,
                        
                        Price ="",

                        Description = description,

                        DescriptionHtml = description,

                        Address1 = registrationModel.Address1,

                        Address2 = registrationModel.Address2,

                        Town = registrationModel.Town,

                        CategoryId = categoryId,

                        Category = listing.SelectSingleNode("category") == null
                            ? string.Empty
                            : listing.SelectSingleNode("category").InnerText,

                        PackageId = listing.SelectSingleNode("packageid") == null
                            ? 0
                            : Convert.ToInt32(listing.SelectSingleNode("packageid").InnerText),

                        Postcode = listing.SelectSingleNode("key[@postcode]") == null
                            ? string.Empty
                            : listing.SelectSingleNode("key[@postcode]").InnerText,

                        Notes = notes

                    };

                    try
                    {
                        var ownerKey = CustomStringHelper.BuildKey(new[] {registrationModel.Email});
                        var ownerId = _ownerServices.GetOwnerIdByKey(ownerKey);
                        _ownerServices.AddListing(ownerId, listingModel);
                    }
                    catch (Exception ex)
                    {
                        errorList.Add(getErrorMessage("listing", listingModel.Address1, ex));
                    }

                }
            }

            return Request.CreateResponse(HttpStatusCode.OK,
                errorList);
        }
Ejemplo n.º 12
0
        public IActionResult EditListing(EditListingViewModel model)
        {
            if (ModelState.IsValid)
            {
                var listing = listingRepo.GetListing(model.Id);
                listing.Title       = model.Title;
                listing.Title       = model.Title;
                listing.Address     = model.Address;
                listing.City        = model.City;
                listing.State       = model.State;
                listing.ZipCode     = model.ZipCode;
                listing.Description = model.Description;
                listing.Price       = model.Price;
                listing.Bedrooms    = model.Bedrooms;
                listing.Bathrooms   = model.Bathrooms;
                listing.Garage      = model.Garage;
                listing.Sqft        = model.Sqft;
                listing.LotSize     = model.LotSize;
                listing.IsPublished = model.IsPublished;
                listing.RealtorId   = model.RealtorId;

                if (model.PhotoMain != null)
                {
                    if (model.ExistingPhotoMain != null)
                    {
                        string filePath = Path.Combine(hostEnvironment.WebRootPath, "images", model.ExistingPhotoMain);
                        System.IO.File.Delete(filePath);
                    }
                    listing.PhotoMain = UploadedFile(model.PhotoMain);
                }
                ;
                if (model.Photo1 != null)
                {
                    if (model.ExistingPhoto1 != null)
                    {
                        string filePath = Path.Combine(hostEnvironment.WebRootPath, "images", model.ExistingPhoto1);
                        System.IO.File.Delete(filePath);
                    }
                    listing.Photo1 = UploadedFile(model.Photo1);
                }
                ;
                if (model.Photo2 != null)
                {
                    if (model.ExistingPhoto2 != null)
                    {
                        string filePath = Path.Combine(hostEnvironment.WebRootPath, "images", model.ExistingPhoto2);
                        System.IO.File.Delete(filePath);
                    }
                    listing.Photo2 = UploadedFile(model.Photo2);
                }
                ;
                if (model.Photo3 != null)
                {
                    if (model.ExistingPhoto3 != null)
                    {
                        string filePath = Path.Combine(hostEnvironment.WebRootPath, "images", model.ExistingPhoto3);
                        System.IO.File.Delete(filePath);
                    }
                    listing.Photo3 = UploadedFile(model.Photo3);
                }
                ;
                if (model.Photo4 != null)
                {
                    if (model.ExistingPhoto4 != null)
                    {
                        string filePath = Path.Combine(hostEnvironment.WebRootPath, "images", model.ExistingPhoto4);
                        System.IO.File.Delete(filePath);
                    }
                    listing.Photo4 = UploadedFile(model.Photo4);
                }
                ;
                if (model.Photo5 != null)
                {
                    if (model.ExistingPhoto5 != null)
                    {
                        string filePath = Path.Combine(hostEnvironment.WebRootPath, "images", model.ExistingPhoto5);
                        System.IO.File.Delete(filePath);
                    }
                    listing.Photo5 = UploadedFile(model.Photo5);
                }
                ;
                if (model.Photo6 != null)
                {
                    if (model.ExistingPhoto6 != null)
                    {
                        string filePath = Path.Combine(hostEnvironment.WebRootPath, "images", model.ExistingPhoto6);
                        System.IO.File.Delete(filePath);
                    }
                    listing.Photo6 = UploadedFile(model.Photo6);
                }
                ;

                Listing updatedListing = listingRepo.Update(listing);
                return(RedirectToAction(nameof(Listings)));
            }
            return(View());
        }
        public void AddListing(int ownerId, EditListingViewModel model)
        {            
            using (var session = NHibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {                   
                    // get existing entities
                    var owner = session.CreateCriteria(typeof (Owner))
                        .List<Owner>().FirstOrDefault(x => x.Id.Equals(ownerId));

                    var categoryId = model.CategoryId;
                    if (categoryId==0) int.TryParse(model.Category, out categoryId);
                    var category = session.CreateCriteria(typeof(Category))
                       .List<Category>().FirstOrDefault(x => x.Id.Equals(categoryId));

                    var packageId = model.PackageId;
                    if (packageId == 0) int.TryParse(model.Package, out packageId);
                    var package = session.CreateCriteria(typeof(PaymentPackage))
                       .List<PaymentPackage>().FirstOrDefault(x => x.Id.Equals(packageId));

                    var addressDetailKey = CustomStringHelper.BuildKey(new[] { model.Address1, model.Postcode });
                   // if (!string.IsNullOrEmpty(model.ListingKey))
                   // {
                   //     addressDetailKey = model.ListingKey;
                   // }

                    // get potentially new entities and save them
                    // address
                    var address = session.CreateCriteria(typeof(AddressDetail))
                        .List<AddressDetail>().FirstOrDefault(x => x.AddressDetailKey.Equals(addressDetailKey)) ??
                                  new AddressDetail();

                    address.Address1 = model.Address1;
                    address.Address2 = model.Address2;
                    address.Town = model.Town;
                    address.Postcode = model.Postcode.ToUpperInvariant();
                    address.IsActive = 1;
                    address.AddressDetailKey = CustomStringHelper.BuildKey(new[] { model.Address1, model.Postcode });

                    addressDetailKey = address.AddressDetailKey;

                    SetAudit(address);
                    session.SaveOrUpdate(address);

                    // contact
                    var contactDetail = session.CreateCriteria(typeof(ContactDetail))
                        .List<ContactDetail>().FirstOrDefault(x => x.ContactDetailKey.Equals(owner.OwnerKey)) ??
                                  new ContactDetail();

                    contactDetail.Website = model.WebsiteUrl;
                    contactDetail.IsActive = 1;
                    contactDetail.ContactDetailKey = owner.OwnerKey;

                    SetAudit(contactDetail);
                    session.SaveOrUpdate(contactDetail); 

                    // location
                    var location = session.CreateCriteria(typeof(Location))
                       .List<Location>().FirstOrDefault(x => 
                           x.Postcode.Equals(model.Postcode)) ??
                                 new Location();

                    // get geolocation from postcode
                    decimal lat = 0;
                    decimal lng = 0;
                    try
                    {
                        var requestUri =
                            string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false",
                                Uri.EscapeDataString(model.Postcode));
                        var request = WebRequest.Create(requestUri);
                        var response = request.GetResponse();
                        var xdoc = XDocument.Load(response.GetResponseStream());
                        decimal.TryParse(xdoc.XPathSelectElement("GeocodeResponse/result/geometry/location/lat").Value,
                            out lat);
                        decimal.TryParse(xdoc.XPathSelectElement("GeocodeResponse/result/geometry/location/lng").Value,
                            out lng);
                    }
                    catch{ }

                    location.Postcode = model.Postcode.ToUpperInvariant();
                    location.Latitude = lat;
                    location.Longitude = lng;
                    location.IsActive = 1;
                    
                    SetAudit(location);
                    session.SaveOrUpdate(location);

                    //if (!string.IsNullOrEmpty(model.ListingKey))
                    //{
                    //    addressDetailKey = model.ListingKey;
                    //}

                    // listing
                    var listing = session.CreateCriteria(typeof(ListingDetail))
                       .List<ListingDetail>().FirstOrDefault(x =>
                           x.ListingKey.Equals(addressDetailKey)) ??
                                 new ListingDetail();

                    listing.Init();                    

                    listing.ExpiraryDate = DateTime.Now;

                    listing.Description = package==null || package.Id == 1
                        ? model.Description
                        : model.DescriptionHtml;

                    listing.StrapLine = model.StrapLine;
                    listing.Price = model.Price;
                    listing.AddressDetail = address;
                    listing.Owner = owner;
                    listing.PaymentPackage = package;
                    listing.Category = category;
                    listing.Location = location;
                    listing.Notes = model.Notes;

                    listing.ListingKey = CustomStringHelper.BuildKey(new[] { model.Address1, model.Postcode });;

                    listing.Notes = model.Notes;

                    SetAudit(listing);
                    listing.IsActive = 1;
                    session.SaveOrUpdate(listing); 

                    // rooms
                    DeleteRooms(session, listing.Id);
                    if (!string.IsNullOrEmpty(model.Rooms))
                    {
                        var rooms = JsonConvert.DeserializeObject<List<RoomViewModel>>(model.Rooms);
                        foreach (var roomViewModel in rooms)
                        {
                            var room = new Room {Description = roomViewModel.Description, Type = roomViewModel.RoomType};
                            room.ListingDetail = listing;
                            SetAudit(room);
                            room.IsActive = 1;
                            session.SaveOrUpdate(room);
                            listing.Rooms.Add(room);
                        }
                    }

                    // theatres
                    DeleteTheatres(session, listing.Id);
                    if (!string.IsNullOrEmpty(model.Theatres))
                    {
                        var theatres = JsonConvert.DeserializeObject<List<TheatreViewModel>>(model.Theatres);
                        foreach (var theatreViewModel in theatres)
                        {
                            var theatre = new Theatre
                            {
                                Name = theatreViewModel.Name,
                                Town = theatreViewModel.Town,
                                Distance = theatreViewModel.Distance,
                                Transport = theatreViewModel.Transport,
                                ListingDetail = listing
                            };
                            SetAudit(theatre);
                            theatre.IsActive = 1;
                            session.SaveOrUpdate(theatre);
                            listing.Theatres.Add(theatre);
                        }
                    }

                    // images
                    DeleteImages(session, listing.Id);
                    if (!string.IsNullOrEmpty(model.Images))
                    {
                        var images = JsonConvert.DeserializeObject<List<ImageViewModel>>(model.Images);
                        foreach (var imageViewModel in images)
                        {
                            var image = new Image
                            {
                                Alt = "Owner Image",
                                ThumbUrl = imageViewModel.File,
                                LargeUrl = imageViewModel.File.Replace("thumbnails/", ""),
                                DisplayOrder = images.IndexOf(imageViewModel),
                                ListingDetail = listing
                            };
                            SetAudit(image);
                            image.IsActive = 1;
                            session.SaveOrUpdate(image);
                            listing.Images.Add(image);
                        }
                    }

                    // tags
                    DeleteTags(session, listing.Id);
                    if (!string.IsNullOrEmpty(model.Tags))
                    {
                        var taglist = model.Tags.Split(',');
                        foreach (var strTag in taglist)
                        {
                            var tag = new Tag {Name = strTag};
                            SetAudit(tag);
                            tag.ListingDetail = listing;
                            tag.IsActive = 1;
                            session.SaveOrUpdate(tag);
                            listing.Tags.Add(tag);
                        }
                    }
                    SetAudit(listing);
                    listing.IsActive = 1;
                    session.SaveOrUpdate(listing); 

                    transaction.Commit();
                }
            }                                                
        }
Ejemplo n.º 14
0
 public static EditListingViewModel Map(EditListingViewModel viewModel, ListingDetail entity)
 {
     return Mapper.Map(entity, viewModel);
 }
Ejemplo n.º 15
0
        public async Task <ActionResult> WishList(EditListingViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = await usrCtx.GetUserAsync(HttpContext.User);

                Course      newCourse  = new Course();
                BookListing newListing = new BookListing();
                newListing.ApplicationUserID = user.Id;
                newListing.Condition         = viewModel.condition;
                newListing.BookID            = viewModel.book.ID;
                newListing.CourseID          = viewModel.courseID;
                newListing.AskingPrice       = viewModel.price;
                newListing.Type = WISHLIST;
                // If they created a new course, add the course to the database.
                if (viewModel.newCourse)
                {
                    newCourse.Dept      = viewModel.courseDept;
                    newCourse.CourseNum = viewModel.courseID;
                    newCourse.Name      = viewModel.courseName;
                    newCourse.SchoolID  = user.SchoolID;
                    ctx.Courses.Add(newCourse);
                    newListing.Course = newCourse;
                }
                else
                {
                    // Connect the book and the  pre-existing course if it doesn't already exist.
                    if (!ctx.BookToCourses.Where(a => a.BookID == viewModel.book.ID && a.CourseID == viewModel.courseID).Any())
                    {
                        BookToCourse bookToCourse = new BookToCourse();
                        bookToCourse.BookID   = viewModel.book.ID;
                        bookToCourse.CourseID = viewModel.courseID;
                        ctx.BookToCourses.Add(bookToCourse);
                    }
                }

                ctx.BookListings.Add(newListing);
                ctx.SaveChanges();

                // Put it after the new course is added and saved into the database so it receives an ID.
                if (viewModel.newCourse)
                {
                    // Connect the book and the new course if it doesn't already exist.
                    if (!ctx.BookToCourses.Where(a => a.BookID == viewModel.book.ID && a.CourseID == newCourse.ID).Any())
                    {
                        BookToCourse bookToCourse = new BookToCourse();
                        bookToCourse.BookID   = viewModel.book.ID;
                        bookToCourse.CourseID = newCourse.ID;
                        ctx.BookToCourses.Add(bookToCourse);
                        ctx.SaveChanges();
                    }
                }

                return(RedirectToAction("Index", "Profile"));
            }
            else
            {
                viewModel.book    = ctx.Books.Where(a => a.ID == viewModel.book.ID).FirstOrDefault();
                viewModel.courses = ctx.Courses.ToList();
                return(View(viewModel));
            }
        }