public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(User);

            CustomerSupport.Username = await _userManager.GetUserNameAsync(user);

            CustomerSupport.DateTimeStamp = DateTime.Now;
            CustomerSupport.Lodger        = user;
            _context.CustomerSupport.Add(CustomerSupport);
            //await _context.SaveChangesAsync();

            if (await _context.SaveChangesAsync() > 0)
            {
                var auditrecord = new AuditRecord();
                auditrecord.AuditActionType = "Add Customer Support Record";
                auditrecord.DateTimeStamp   = DateTime.Now;
                auditrecord.PerformedBy     = user;
                auditrecord.AuditRecordId   = Guid.NewGuid().ToString();
                auditrecord.IPAddress       = HttpContext.Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                _context.AuditRecords.Add(auditrecord);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(string listingid)
        {
            EntityEntry entry = _context.Entry(Review);

            Listing = await _context.Listing.FirstOrDefaultAsync(m => m.ListingId == listingid);

            Review.Listing = Listing;
            Review.Lodger  = await userManager.GetUserAsync(User);

            Review.DateTime = DateTime.Now;

            var errors = ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception));

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Review).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                // Create an auditrecord object
                var auditrecord = new AuditRecord();
                auditrecord.AuditActionType = "Review " + Review.ReviewId + " was edited";
                auditrecord.DateTimeStamp   = DateTime.Now;
                // Get current logged-in user
                auditrecord.PerformedBy = await userManager.GetUserAsync(User);

                auditrecord.IPAddress = auditrecord.PerformedBy.IPAddress;
                _context.AuditRecords.Add(auditrecord);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReviewExists(Review.ReviewId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Redirect("./ListingDetails?id=" + Listing.ListingId));
        }
示例#3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            Lodger = await _userManager.GetUserAsync(User);

            if (Lodger == null)
            {
                var auditrecord = new AuditRecord();
                auditrecord.AuditActionType = "Anonymous User Tried To Edit Customer Support id:" + id + " Record";
                auditrecord.DateTimeStamp   = DateTime.Now;
                auditrecord.PerformedBy     = null;
                auditrecord.AuditRecordId   = Guid.NewGuid().ToString();
                auditrecord.IPAddress       = HttpContext.Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                _context.AuditRecords.Add(auditrecord);
                await _context.SaveChangesAsync();

                return(RedirectToPage("/Error/NiceTry"));
            }

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

            CustomerSupport = await _context.CustomerSupport.FirstOrDefaultAsync(m => m.CustomerSupport_ID == id);

            if (Lodger.Id != CustomerSupport.Lodger.Id)
            {
                var user = await _userManager.GetUserAsync(User);

                var auditrecord = new AuditRecord();
                auditrecord.AuditActionType = "User Tried To Edit Another User's Customer Support" + id + " Record";
                auditrecord.DateTimeStamp   = DateTime.Now;
                auditrecord.PerformedBy     = user;
                auditrecord.AuditRecordId   = Guid.NewGuid().ToString();
                auditrecord.IPAddress       = HttpContext.Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                _context.AuditRecords.Add(auditrecord);
                await _context.SaveChangesAsync();

                return(RedirectToPage("/Error/NiceTry"));
            }

            CustomerSupport = await _context.CustomerSupport.FirstOrDefaultAsync(m => m.CustomerSupport_ID == id);

            if (CustomerSupport == null)
            {
                return(NotFound());
            }
            return(Page());
        }
示例#4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(CreditCard).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CreditCardExists(CreditCard.CreditCardId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Review.Add(Review);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
示例#6
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            Lodger = await _userManager.GetUserAsync(User);

            if (Lodger == null)
            {
                var auditrecord = new AuditRecord();
                auditrecord.AuditActionType = "Anonymous User Tried To Access Thread id:" + id + " Record";
                auditrecord.DateTimeStamp   = DateTime.Now;
                auditrecord.PerformedBy     = null;
                auditrecord.AuditRecordId   = Guid.NewGuid().ToString();
                auditrecord.IPAddress       = HttpContext.Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                _context.AuditRecords.Add(auditrecord);
                await _context.SaveChangesAsync();

                return(RedirectToPage("/Error/NiceTry"));
            }

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

            CustomerSupport = await _context.CustomerSupport.FirstOrDefaultAsync(m => m.CustomerSupport_ID == id);


            HttpContext.Session.SetInt32("currentId", Convert.ToInt32(id));
            CustomerSupport = await _context.CustomerSupport.FirstOrDefaultAsync(m => m.CustomerSupport_ID == HttpContext.Session.GetInt32("currentId"));

            Replies = await _context.Reply.Where(r => r.CustomerSupport_ID == CustomerSupport.CustomerSupport_ID).ToListAsync();

            if (CustomerSupport == null)
            {
                return(NotFound());
            }
            return(Page());
        }
示例#7
0
        public async Task <IActionResult> OnPostRevertChangesAsync()
        {
            if (!(ModelState.IsValid))
            {
                return(Page());
            }
            AuditRecord usingAuditRecord = _context.AuditRecords.First(ar => (ar.AuditRecordId == auditRecordId));

            if (usingAuditRecord == null)
            {
                ModelState.AddModelError("Error!", "Audit Record Not Found!");
                return(Page());
            }
            Lodger cu = _context.Users.First(u => (u.Id == usingAuditRecord.PerformedBy.Id));

            if (!(cu is Lodger))
            {
                ModelState.AddModelError("Error!", "User Not Found!");
                return(Page());
            }
            UserRevert rt = _context.UserReverts.First(ur => (ur.AuditRecord.AuditRecordId == usingAuditRecord.AuditRecordId));

            if (rt == null)
            {
                ModelState.AddModelError("Error!", "Revert Backup not found!");
                return(Page());
            }
            cu.FullName             = rt.FullName;
            cu.Gender               = rt.Gender;
            cu.AlternateEmail       = rt.AlternateEmail;
            cu.Country              = rt.Country;
            cu.City                 = rt.City;
            cu.Occupation           = rt.Occupation;
            cu.Address              = rt.Address;
            cu.GovernmentID         = rt.GovernmentID;
            cu.Status               = rt.Status;
            cu.Biography            = rt.Biography;
            cu.Hobbies              = rt.Hobbies;
            cu.Email                = rt.Email;
            cu.PasswordHash         = rt.PasswordHash;
            cu.PhoneNumber          = rt.PhoneNumber;
            cu.PhoneNumberConfirmed = rt.PhoneNumberConfirmed;
            cu.is3AuthEnabled       = rt.is3AuthEnabled;
            await _context.SaveChangesAsync();

            return(RedirectToPage());
        }
示例#8
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Booking = await _context.Booking.FindAsync(id);

            if (Booking != null)
            {
                _context.Booking.Remove(Booking);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./MyBookings"));
        }
示例#9
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CreditCard = await _context.CreditCard.FindAsync(id);

            if (CreditCard != null)
            {
                _context.CreditCard.Remove(CreditCard);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#10
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Review = await _context.Review.FindAsync(id);

            if (Review != null)
            {
                _context.Review.Remove(Review);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#11
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            Lodger = await userManager.GetUserAsync(User);

            var creator = (from l in _context.Listing where l.ListingId == id select l.Lodger.Id).ToList();

            if (Lodger.Id == creator[0])
            {
                var existingPic = (from l in _context.Listing where l.ListingId == id select l.CoverPic).ToList();

                if (!ModelState.IsValid)
                {
                    return(Page());
                }

                if (Upload != null)
                {
                    VirusReport vr = await ScanForVirus(Upload);

                    if (vr.Positives > 0)
                    {
                        ModelState.AddModelError("CoverPicFailedVirusCheck", "Cover Picture failed virus scan!");
                        ModelState.AddModelError("CoverPicReportLink", vr.ReportLink);
                        return(Page());
                    }

                    changePic = true;

                    string fullPath = "./wwwroot/ListingCover/" + existingPic[0];
                    fullPath = Path.GetFullPath(fullPath);

                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }

                    var filename = Guid.NewGuid().ToString() + Path.GetExtension(Upload.FileName);
                    var file     = Path.Combine(_environment.ContentRootPath, "wwwroot", "ListingCover", filename);

                    using (var fileStream = new FileStream(file, FileMode.Create))
                    {
                        await Upload.CopyToAsync(fileStream);

                        using (var ms = new MemoryStream())
                        {
                            Upload.CopyTo(ms);
                            var fileBytes = ms.ToArray();
                            hex = BitConverter.ToString(fileBytes).Replace("-", "").Substring(0, 4);

                            if (!allowedFileTypes.Contains(hex))
                            {
                                return(RedirectToPage("/Error/wrongFileType"));
                            }


                            Listing.CoverPic = filename;
                        }
                    }
                }

                _context.Attach(Listing).State = EntityState.Modified;

                if (!changePic)
                {
                    Listing.CoverPic = existingPic[0];
                    _context.Listing.Update(Listing);
                }

                try
                {
                    await _context.SaveChangesAsync();

                    // Create an auditrecord object
                    var auditrecord = new AuditRecord();
                    auditrecord.AuditActionType = "Listing " + Listing.ListingId + " was edited";
                    auditrecord.DateTimeStamp   = DateTime.Now;
                    // Get current logged-in user
                    auditrecord.PerformedBy = await userManager.GetUserAsync(User);

                    auditrecord.IPAddress = auditrecord.PerformedBy.IPAddress;
                    _context.AuditRecords.Add(auditrecord);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ListingExists(Listing.ListingId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToPage("./Listings"));
            }
            else
            {
                return(RedirectToPage("./Error/NiceTry"));
            }
        }