예제 #1
0
        public ListingModel ReadListData(int id)
        {
            ListingModel ListModel = new ListingModel();
            DataTable    dtbllist  = new DataTable();

            using (SqlConnection sqlConn = new SqlConnection(Sql.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("spListing", sqlConn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@StatementType", "SelectEdit");
                cmd.Parameters.AddWithValue("@listid", id);
                sqlConn.Open();
                SqlDataReader sqlread = cmd.ExecuteReader();
                dtbllist.Load(sqlread);
                sqlConn.Close();
            }
            if (dtbllist.Rows.Count == 1)
            {
                ListModel.ListingID        = Convert.ToInt32(dtbllist.Rows[0][0].ToString());
                ListModel.ListingImg       = dtbllist.Rows[0][1].ToString();
                ListModel.ListingProd      = dtbllist.Rows[0][2].ToString();
                ListModel.ListingProdTitle = dtbllist.Rows[0][3].ToString();
                ListModel.ListingDetail    = dtbllist.Rows[0][4].ToString();
            }
            return(ListModel);
        }
        public List <ListingModel> GetWishlistItems(int wishlistId)
        {
            var wishlistItems = _context.WishlistListing.Where(x => x.WishlistId == wishlistId).ToList();
            var result        = new List <ListingModel>();

            foreach (var item in wishlistItems)
            {
                var listing         = _context.Listing.First(x => x.ListingId == item.ListingId);
                var newListingModel = new ListingModel
                {
                    ListingId = listing.ListingId,
                    Bathrooms = listing.Bathrooms,
                    Beds      = listing.Beds,
                    City      = listing.City,
                    Name      = listing.Name,
                    Persons   = listing.Persons
                };
                if (_context.ListingImage.Any(x => x.ListingId == item.ListingId))
                {
                    newListingModel.Image = _context.ListingImage.FirstOrDefault(x => x.ListingId == item.ListingId).Image;
                }
                result.Add(newListingModel);
            }
            return(result);
        }
예제 #3
0
        public async Task <ActionResult <string> > Post(ListingModel L)
        {
            //TODO : Validate Model
            //https://docs.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-3.1

            try
            {
                var listing = await _listingService.GetByListingID(L.ListingID);

                if (listing == null)
                {
                    var id = await _listingService.Post(L);

                    Response.StatusCode = 201;
                    return(Content($"resource with {id} was created"));
                }
                else
                {
                    Response.StatusCode = 400;
                    return(Content("Listing already exsists"));
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = 400;
                return(Content(ex.Message));
            }
        }
예제 #4
0
        public void UpdateListingTest()
        {
            ManageController controller   = new ManageController();
            ListingModel     listingModel = controller.ReturnLastAddedListing();
            ListingInfo      listing      = new ListingInfo();

            listing.Id          = listingModel.Id;
            listing.Title       = "Unit Test (Updated)";
            listing.StartDate   = listingModel.StartDate;
            listing.EndDate     = listingModel.EndDate;
            listing.Area        = listingModel.Area;
            listing.Frequency   = listingModel.Frequency;
            listing.Description = "Unit testing... again!";
            listing.HangoutUrl  = listingModel.HangoutUrl;
            listing.TeacherId   = listingModel.TeacherId;
            listing.Open        = listingModel.Open;
            listing.Teacher     = "*****@*****.**";

            //Check that the UpdateListing function completed successfully
            Assert.AreEqual(controller.UpdateListing(listing), "Listing Updated");

            //Check that the listing was actually updated in the database
            ListingModel lastAdded = controller.ReturnLastAddedListing();

            Assert.IsTrue(listing.Title == lastAdded.Title &&
                          listing.StartDate == lastAdded.StartDate &&
                          listing.EndDate == lastAdded.EndDate &&
                          listing.Area == lastAdded.Area &&
                          listing.Frequency == lastAdded.Frequency &&
                          listing.Description == lastAdded.Description &&
                          listing.HangoutUrl == lastAdded.HangoutUrl &&
                          listing.TeacherId == lastAdded.TeacherId &&
                          listing.Open == lastAdded.Open);
        }
예제 #5
0
        public ListingModel GetListingOnly(int id)
        {
            ListingModel myItem = _context.Items.FirstOrDefault(x => x.Id == id);

            //ListingModel myItem = _context.Items.Include(list => list.Images).FirstOrDefault(x => x.Id == id);
            return(myItem);
        }
예제 #6
0
        public void AddListingTest()
        {
            ManageController controller = new ManageController();
            ListingModel     listing    = new ListingModel();

            listing.Title       = "Unit Test";
            listing.StartDate   = new DateTime(2016, 3, 20, 12, 00, 00);
            listing.EndDate     = new DateTime(2016, 3, 21, 12, 00, 00);
            listing.Area        = "History";
            listing.Frequency   = "Always";
            listing.Description = "Unit testing!";
            listing.HangoutUrl  = "what.com";
            listing.TeacherId   = 5;
            listing.Open        = false;

            //Testing the AddListing function
            controller.AddListing(listing);

            //Check that the listing was actually added to the database
            ListingModel lastAdded = controller.ReturnLastAddedListing();

            Assert.IsTrue(listing.Title == lastAdded.Title &&
                          listing.StartDate == lastAdded.StartDate &&
                          listing.EndDate == lastAdded.EndDate &&
                          listing.Area == lastAdded.Area &&
                          listing.Frequency == lastAdded.Frequency &&
                          listing.Description == lastAdded.Description &&
                          listing.HangoutUrl == lastAdded.HangoutUrl &&
                          listing.TeacherId == lastAdded.TeacherId &&
                          listing.Open == lastAdded.Open);
        }
예제 #7
0
        public ListingModel AddListing(ListingModel listing)
        {
            if (listing != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    try
                    {
                        db.ListingModels.Add(listing);
                        db.SaveChanges();

                        //Return the listing because it now has its new Id
                        return(listing);
                    }
                    catch (Exception err)
                    {
                        return(null);
                    }
                }
            }
            else
            {
                return(null);
            }
        }
예제 #8
0
        public string DeleteListing(ListingModel listing)
        {
            if (listing != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    var l = db.ListingModels.Where(x => x.Id == listing.Id).FirstOrDefault();

                    if (l != null)
                    {
                        DeleteAssociatedAssignments(l);
                        DeleteAssociatedApplications(l);

                        db.ListingModels.Remove(l);
                        db.SaveChanges();
                        return("Listing Deleted");
                    }
                    else
                    {
                        return("Invalid Listing");
                    }
                }
            }
            else
            {
                return("Invalid Listing");
            }
        }
예제 #9
0
        public ActionResult Edit(string listingID, bool Internal = false)
        {
            var serialization = new Serialization();
            var listingsBA    = new Listings();
            var HashCriteria  = new Hashtable();
            var listingsModel = new ListingModel();
            var listing_ID    = Convert.ToInt64(CipherTool.DecryptString(listingID));

            listingsModel.loanInformation = new LoanInformation();
            var dropdownValues = new LoanInformation();

            HashCriteria.Add("UserID", userID);
            HashCriteria.Add("ID", listing_ID);
            HashCriteria.Add("CurrentTab", "LoanInformation");
            var actualCriteria   = serialization.SerializeBinary((object)HashCriteria);
            var result           = listingsBA.EditCurrentListing(actualCriteria);
            var listingEditModel = (LoanInformation)(serialization.DeSerializeBinary(Convert.ToString(result)));
            var defaultValues    = listingsBA.GetListingDefaultValuesForLoanInformation();

            dropdownValues = (LoanInformation)(serialization.DeSerializeBinary(Convert.ToString(defaultValues)));
            listingEditModel.ListingType                   = GetListingLoanType();
            listingEditModel.RateType                      = dropdownValues.RateType;
            listingEditModel.AmortizationType              = dropdownValues.AmortizationType;
            listingEditModel.PaymentsFrequency             = dropdownValues.PaymentsFrequency;
            listingEditModel.LienPositionType              = dropdownValues.LienPositionType;
            listingEditModel.JuniorTrustDeedORMortgageList = dropdownValues.JuniorTrustDeedORMortgageList;
            listingsModel.loanInformation                  = listingEditModel;
            if (Internal)
            {
                return(PartialView("_LoanInformation", listingsModel.loanInformation));
            }

            return(View("AddListing", listingsModel));
        }
예제 #10
0
        public void GetListingsTest()
        {
            ManageController controller = new ManageController();

            var JSONListings = controller.GetListings();

            string stringListings = JsonConvert.SerializeObject(JSONListings.Data);

            List <ListingInfo> ListListings = JsonConvert.DeserializeObject <List <ListingInfo> >(stringListings);

            ListingInfo test = ListListings.Last();

            ListingModel listing = new ListingModel();

            listing.Title       = "Unit Test (Updated)";
            listing.StartDate   = new DateTime(2016, 3, 20, 12, 00, 00);
            listing.EndDate     = new DateTime(2016, 3, 21, 12, 00, 00);
            listing.Area        = "History";
            listing.Frequency   = "Always";
            listing.Description = "Unit testing... again!";
            listing.HangoutUrl  = "what.com";
            listing.TeacherId   = 5;
            listing.Open        = false;

            //Check that all listings were returned by checking for a specific listing
            Assert.IsTrue(listing.Title == test.Title &&
                          listing.StartDate == test.StartDate &&
                          listing.EndDate == test.EndDate &&
                          listing.Area == test.Area &&
                          listing.Frequency == test.Frequency &&
                          listing.Description == test.Description &&
                          listing.HangoutUrl == test.HangoutUrl &&
                          listing.TeacherId == test.TeacherId &&
                          listing.Open == test.Open);
        }
예제 #11
0
        public async Task <ActionResult> Dashboard(string searchText)
        {
            var userId = User.Identity.GetUserId();
            var items  = await _listingService.Query(x => x.UserID == userId).Include(x => x.ListingPictures).SelectAsync();

            // Filter string
            if (!string.IsNullOrEmpty(searchText))
            {
                items = items.Where(x => x.Title.ToLower().Contains(searchText.ToLower().ToString()));
            }

            var itemsModel = new List <ListingItemModel>();

            foreach (var item in items.OrderByDescending(x => x.Created))
            {
                itemsModel.Add(new ListingItemModel()
                {
                    ListingCurrent = item,
                    UrlPicture     = item.ListingPictures.Count == 0 ? ImageHelper.GetListingImagePath(0) : ImageHelper.GetListingImagePath(item.ListingPictures.OrderBy(x => x.Ordering).FirstOrDefault().PictureID)
                });
            }

            var model = new ListingModel()
            {
                Listings = itemsModel
            };

            return(View(model));
        }
예제 #12
0
        public IHttpActionResult PutListingModel(int id, ListingModel listingModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != listingModel.Id)
            {
                return(BadRequest());
            }

            db.Entry(listingModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ListingModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #13
0
        public string GetListingDefaultValuesForPropertyInformation()
        {
            var          listingService = this.GetServiceClient();
            ListingModel lstListings    = new ListingModel();
            var          result         = listingService.GetListingDefaultValuesForPropertyInformation();

            return(result);
        }
예제 #14
0
        public IActionResult ListingPage()
        {
            ListingModel currentListing = getCurrentListing(Request.Path);

            ViewData["theListings"] = SuperPortlandListings.Program.theListings;
            ViewData["projectDate"] = SuperPortlandListings.Program.projectDate;
            return(View(currentListing));
        }
예제 #15
0
        public async Task <IActionResult> AddAttachments(ListingAttachmentModel Attachments)
        {
            List <Pictures> picturesToAdd = new List <Pictures>();
            ListingModel    Listings      = new ListingModel();

            if (!string.IsNullOrEmpty(Attachments.ListingId))
            {
                Listings = await _listingService.GetByID(Attachments.ListingId);

                if (Listings == null)
                {
                    Response.StatusCode = 400;
                    return(Content("Listing Not found"));
                }
                else
                {
                    picturesToAdd = Listings.Pictures;
                    foreach (string attachmentPath in Attachments.AttachmentPaths)
                    {
                        var pictureUrl = Guid.NewGuid().ToString();
                        picturesToAdd.Add(new Pictures {
                            TypeID = PictureType.Featured, url = pictureUrl
                        });
                        try
                        {
                            await _s3Service.uploadFile(pictureUrl, attachmentPath);
                        }
                        catch (Exception)
                        {
                            Response.StatusCode = 400;
                            return(Content("We Could not upload all the pictures please try again"));
                        }
                    }
                    UpdateDefinition <ListingModel> update = Builders <ListingModel> .Update.Set(l => l.Pictures, picturesToAdd);

                    FilterDefinition <ListingModel> Mongofilter = Builders <ListingModel> .Filter.Eq(l => l.Id, Attachments.ListingId);

                    try
                    {
                        await _listingService.UpdateListing(Mongofilter, update);
                    }
                    catch (Exception)
                    {
                        Response.StatusCode = 400;
                        return(Content("We Could not upload all the pictures please try again"));
                    }

                    Response.StatusCode = 200;
                    return(Content("All the attachmens Were Added"));
                }
            }
            else
            {
                Response.StatusCode = 400;
                return(Content("Please send in the listing ID"));
            }
        }
예제 #16
0
 public ListingController(IListingServices services, ICreateList listCreate, IReadList listRead, IEditList listEdit, IDeleteList listDelete, ListingModel modelList)
 {
     this.ListingServices = services;
     this.CreateList      = listCreate;
     this.ReadList        = listRead;
     this.EditList        = listEdit;
     this.DeleteList      = listDelete;
     this.ListModelc      = modelList;
 }
예제 #17
0
        public string GetTeacherName(ListingModel listing)
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var teacher = db.iMentorUsers.Where(x => x.Id == listing.TeacherId).FirstOrDefault();
                var result  = teacher.UserName;

                return(result);
            }
        }
예제 #18
0
 public ListingModel Add(ListingModel newListing)
 {
     foreach (Images myImage in newListing.Images)
     {
         _context.Add(myImage);
     }
     _context.Add(newListing);
     _context.SaveChanges();
     return(newListing);
 }
예제 #19
0
        public IHttpActionResult GetListingModel(int id)
        {
            ListingModel listingModel = db.ListingModels.Find(id);

            if (listingModel == null)
            {
                return(NotFound());
            }

            return(Ok(listingModel));
        }
예제 #20
0
        public IActionResult Index()
        {
            var clubList = _listingService.GetClubs();

            var model = new ListingModel()
            {
                Clubs = clubList
            };

            return(View(model));
        }
예제 #21
0
        public IHttpActionResult PostListingModel(ListingModel listingModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ListingModels.Add(listingModel);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = listingModel.Id }, listingModel));
        }
예제 #22
0
 public ActionResult Create(ListingModel ListModel)
 {
     if (ModelState.IsValid)
     {
         SqlDataReader sqlRead = CreateList.CreateProdList(ListModel);
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         return(View(ListModel));
     }
 }
예제 #23
0
 // GET: Listing/Edit/5
 public ActionResult Edit(int id)
 {
     if (ModelState.IsValid)
     {
         ListModelc = ReadList.ReadListData(id);
         return(View(ListModelc));
     }
     else
     {
         return(View(ListModelc));
     }
 }
예제 #24
0
 public ActionResult Edit(ListingModel ListModel)
 {
     if (ModelState.IsValid)
     {
         SqlDataReader sqlread = EditList.EditListData(ListModel);
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         return(View(ListModel));
     }
 }
예제 #25
0
        public ActionResult Listings()
        {
            var grid       = new ListingsGrid(_listingService.Query().Include(x => x.ListingType).Select().OrderByDescending(x => x.Created).AsQueryable());
            var categories = CacheHelper.Categories;

            var model = new ListingModel()
            {
                Categories = categories,
                Grid       = grid
            };

            return(View(model));
        }
예제 #26
0
        private void DeleteAssociatedAssignments(ListingModel listing)
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var assignments = db.AssignedListings.Where(x => x.ListingId == listing.Id).ToList();

                foreach (AssignedListing assignment in assignments)
                {
                    db.AssignedListings.Remove(assignment);
                    db.SaveChanges();
                }
            }
        }
예제 #27
0
        private void DeleteAssociatedApplications(ListingModel listing)
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var applicants = db.Applicants.Where(x => x.ListingId == listing.Id).ToList();

                foreach (Applicant applicant in applicants)
                {
                    db.Applicants.Remove(applicant);
                    db.SaveChanges();
                }
            }
        }
예제 #28
0
        public IHttpActionResult DeleteListingModel(int id)
        {
            ListingModel listingModel = db.ListingModels.Find(id);

            if (listingModel == null)
            {
                return(NotFound());
            }

            db.ListingModels.Remove(listingModel);
            db.SaveChanges();

            return(Ok(listingModel));
        }
예제 #29
0
        public async Task <IActionResult> Create(ListingModel _newListing, List <IFormFile> Images)
        {
            if (ModelState.IsValid)
            {
                var newListing = _newListing;
                newListing.Images = await ToImageList(Images);

                var user = await _userManager.GetUserAsync(User);

                newListing.CreatedBy = user.Id;
                newListing.IsActive  = true;
                _model.Add(newListing);
                return(RedirectToAction(nameof(ViewItem), new { id = newListing.Id }));
            }
            return(View());
        }
예제 #30
0
        public ActionResult AddListing()
        {
            Session["ListingDocuments"] = null;
            Session["ListingImages"]    = null;
            var serialization = new Serialization();
            var listingsBA    = new Listings();
            var listingModel  = new ListingModel();

            listingModel.loanInformation = new LoanInformation();
            var loanInformation = new LoanInformation();
            var result          = listingsBA.GetListingDefaultValuesForLoanInformation();

            loanInformation              = (LoanInformation)(serialization.DeSerializeBinary(Convert.ToString(result)));
            loanInformation.ListingType  = GetListingLoanType();
            listingModel.loanInformation = loanInformation;
            return(View(listingModel));
        }