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

            _context.Attach(CommonAreaAsset).State = EntityState.Modified;
            CommonAreaAsset.Status           = "Active";
            CommonAreaAsset.LastModifiedDate = DateTime.Now;
            var user = _context.Owner.FirstOrDefault(x => x.User.UserID == HttpContext.Session.GetInt32("SessionUserID"));

            CommonAreaAsset.LastModifiedBy = user != null ? user.Initials : "SYS";

            try {
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException) {
                if (!CommonAreaAssetExists(CommonAreaAsset.CommonAreaAssetID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Maintenance = await _context.Maintenance.FindAsync(id).ConfigureAwait(false);

            Maintenance.LastModifiedDate = DateTime.Now;
            var user = _context.Owner.FirstOrDefault(x => x.User.UserID == HttpContext.Session.GetInt32("SessionUserID"));

            Maintenance.LastModifiedBy = user != null ? user.Initials : "SYS";

            Maintenance.IsArchive = true;

            _context.Attach(Maintenance).State = EntityState.Modified;
            if (Maintenance != null)
            {
                // _context.Maintenance.Remove(Maintenance);

                await _context.SaveChangesAsync().ConfigureAwait(false);
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

            var user = _context.Owner.FirstOrDefault(x => x.User.UserID == HttpContext.Session.GetInt32("SessionUserID"));

            Owner.LastModifiedBy         = user != null ? user.Initials : "SYS";
            Owner.LastModifiedDate       = DateTime.Now;
            Owner.IsArchive              = true;
            _context.Attach(Owner).State = EntityState.Modified;

            if (Owner.Address != null)
            {
                Owner.Address.LastModifiedBy         = user != null ? user.Initials : "SYS";
                Owner.Address.LastModifiedDate       = DateTime.Now;
                Owner.Address.IsArchive              = true;
                _context.Attach(Owner.Address).State = EntityState.Modified;
            }

            if (Owner.OwnerContactType != null)
            {
                foreach (var contact in Owner.OwnerContactType)
                {
                    OwnerContactType contactToRemove = Owner
                                                       .OwnerContactType
                                                       .SingleOrDefault(c => c.ContactTypeID == contact.ContactTypeID);
                    _context.Remove(contactToRemove);
                }
            }

            if (Owner.CoOwner != null)
            {
                var coowner = _context.Owner.FirstOrDefault(x => x.OwnerID == Owner.CoOwnerID);
                coowner.LastModifiedBy         = user != null ? user.Initials : "SYS";
                coowner.LastModifiedDate       = DateTime.Now;
                coowner.IsArchive              = true;
                _context.Attach(coowner).State = EntityState.Modified;
            }

            if (Owner.User != null)
            {
                Owner.User.LastModifiedBy         = user != null ? user.Initials : "SYS";
                Owner.User.LastModifiedDate       = DateTime.Now;
                Owner.User.IsArchive              = true;
                _context.Attach(Owner.User).State = EntityState.Modified;
            }

            try {
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException) {
                if (!OwnerExists(Owner.OwnerID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int id, IList <IFormFile> formFiles)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var classifiedListing = _context.ClassifiedListing.FirstOrDefault(i => i.ClassifiedListingID == id);

            if (await TryUpdateModelAsync <ClassifiedListing>(
                    classifiedListing,
                    "classifiedListing",
                    s => s.ClassifiedListingID, s => s.ClassifiedCategoryID, s => s.ItemName, s => s.Price, s => s.Description, s => s.Phone, s => s.Email).ConfigureAwait(false))
            {
                classifiedListing.LastModifiedDate = DateTime.Now;
                classifiedListing.ListingDate      = DateTime.Now;

                var owner = _context.Owner.FirstOrDefault(x => x.User.UserID == HttpContext.Session.GetInt32("SessionUserID"));
                classifiedListing.LastModifiedBy = owner.FirstName.Substring(0, 1) + owner.LastName.Substring(0, 1);
                classifiedListing.OwnerID        = owner.OwnerID;

                if (formFiles.Any())
                {
                    var files = _context.File.Where(x => x.ClassifiedListingID == id);
                    if (files.Any())
                    {
                        _context.File.RemoveRange(files);
                    }

                    foreach (var file in formFiles)
                    {
                        if (file.ContentType == "image/jpeg" || file.ContentType == "image/jpg" || file.ContentType == "image/png")
                        {
                            classifiedListing.SetImage(file);
                        }
                        else
                        {
                            ModelState.AddModelError("file", "Invalid file format. Please only enter jpeg or png.");
                            ClassifiedListing = await _context.ClassifiedListing
                                                .Include(c => c.Owner).Include(c => c.Files).FirstOrDefaultAsync(m => m.ClassifiedListingID == id);

                            PopulateCategoryDropDownList(_context);
                            return(Page());
                        }
                    }
                }
                else
                {
                    ClassifiedListing c = _context.ClassifiedListing.AsQueryable().AsNoTracking().FirstOrDefault(x => x.ClassifiedListingID == id);
                    classifiedListing.Files = c.Files;
                }

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

                await _context.SaveChangesAsync().ConfigureAwait(false);

                return(RedirectToPage("./Index"));
            }

            PopulateCategoryDropDownList(_context, classifiedListing.ClassifiedCategoryID);
            return(Page());
        }