コード例 #1
0
        public async Task <IActionResult> OnPostAsync(int?id, string ownerName, string lotNumber)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (ownerName == null)
            {
                ModelState.AddModelError("Account", "You must specify an owner.");
                return(await OnGetAsync(id));
            }

            var ownerLotNumbers = _context.Lots
                                  .Where(x => x.Owner.FullName == ownerName).Select(x => x.LotNumber).ToList();

            if (!ownerLotNumbers.Contains(lotNumber))
            {
                ModelState.AddModelError("LotNumber", "That lot does not currently belog to that owner.");
                return(await OnGetAsync(id));
            }

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

            OwnerHistory.LastModifiedBy   = user != null ? user.Initials : "SYS";
            OwnerHistory.LastModifiedDate = DateTime.Now;

            OwnerHistory.OwnerID = _context.Owner.FirstOrDefault(o => o.FullName == ownerName).OwnerID;

            if (!string.IsNullOrEmpty(lotNumber))
            {
                OwnerHistory.LotID = _context.Lots.FirstOrDefault(l => l.LotNumber == lotNumber).LotID;
            }
            else
            {
                OwnerHistory.LotID = null;
            }

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

            try {
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException) {
                if (!OwnerHistoryExists(OwnerHistory.OwnerHistoryID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            var uId = HttpContext.Session.GetInt32("SessionUserID");

            if (uId == null)
            {
                return(RedirectToPage("./User/Login"));
            }

            if (id == null)
            {
                return(NotFound());
            }
            if (!ModelState.IsValid)
            {
                return(Redirect("./Index"));
            }

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

            Key.LastModifiedBy   = user != null ? user.Initials : "SYS";
            Key.LastModifiedDate = DateTime.Now;

            Key.KeyHistory.Status       = "Returned";
            Key.KeyHistory.DateReturned = DateTime.Now;
            _context.Attach(Key).State  = EntityState.Modified;

            if (KeyHistoryExists(Key.KeyID, Key.KeyHistory.KeyHistoryID))
            {
                Key.KeyHistory.LastModifiedBy         = user != null ? user.Initials : "SYS";
                Key.KeyHistory.LastModifiedDate       = DateTime.Now;
                Key.KeyHistory.Status                 = "Returned";
                _context.Attach(Key.KeyHistory).State = EntityState.Modified;
            }
            else
            {
                Key.KeyHistory = null;
            }

            try {
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException) {
                if (!KeyExists(Key.KeyID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Redirect("./Index"));
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedInventory, string ownerName = "")
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var lotToUpdate = await _context.Lots
                              .Include(l => l.LotInventory).ThenInclude(l => l.Inventory)
                              .Include(l => l.Address).ThenInclude(a => a.Owner)
                              .FirstOrDefaultAsync(l => l.LotID == id);

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

            lotToUpdate.LastModifiedBy   = user != null ? user.Initials : "SYS";
            lotToUpdate.LastModifiedDate = DateTime.Now;

            if (await TryUpdateModelAsync <Lot>(
                    lotToUpdate, "Lot",
                    l => l.Status, l => l.LotNumber, l => l.Address,
                    l => l.LastModifiedBy, l => l.LastModifiedDate))
            {
                if (ownerName == null || lotToUpdate.Status == "Vacant")
                {
                    lotToUpdate.OwnerID = null;
                }
                else
                {
                    var owner = _context.Owner.FirstOrDefault(x => x.FullName == ownerName);
                    if (owner != null)
                    {
                        lotToUpdate.OwnerID = owner.OwnerID;
                    }
                    else
                    {
                        ModelState.AddModelError("Owner", "Please enter the name of an existing primary owner.");
                        await OnGetAsync(id);

                        return(Page());
                    }
                }

                UpdateLotInventory(_context, selectedInventory, lotToUpdate, id);
                await _context.SaveChangesAsync();

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

            UpdateLotInventory(_context, selectedInventory, lotToUpdate, id);
            PopulateAssignedLotInventoryData(_context, lotToUpdate);
            return(RedirectToPage("./Index"));
        }
コード例 #4
0
        public async Task <IActionResult> OnPostAsync(int?id, string ownerName = "")
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            if (KeyHistoryExists(Key.KeyID, Key.KeyHistory.KeyHistoryID))
            {
                Key.LastModifiedBy = user != null ? user.Initials : "SYS";
                Key.KeyHistory.LastModifiedDate = DateTime.Now;
                if ((Key.KeyHistory?.Status == "Returned" || Key.KeyHistory?.Status == "Lost") && Key.KeyHistory?.DateReturned == null)
                {
                    Key.KeyHistory.DateReturned = DateTime.Now;
                }
                if (Key.KeyHistory?.Status == "Active")
                {
                    Key.KeyHistory.DateReturned = null;
                }
                Key.KeyHistory.OwnerID = _context.Owner.FirstOrDefault(x => x.FullName == ownerName).OwnerID;
                _context.Attach(Key.KeyHistory).State = EntityState.Modified;
            }
            else
            {
                KeyHistory keyHistory = Key.KeyHistory;
                _context.KeyHistory.Add(keyHistory);
            }

            try {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) {
                if (!KeyExists(Key.KeyID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Item = await _context.Transaction.FindAsync(id);

            Item.Status   = "Paid";
            Item.DatePaid = DateTime.Now;

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

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

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

            return(RedirectToPage("./Index"));
        }
コード例 #6
0
        public async Task <IActionResult> OnPostAsync(string ownerName = "")
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            IQueryable <Models.Owner> ownerIQ = from u in _context.Owner select u;

            bool temp = false;

            foreach (var own in ownerIQ)
            {
                if (own.FullName == ownerName)
                {
                    temp = true;
                    break;
                }
            }


            var owners = _context.Owner.Select(x => x.FullName).ToList();

            if (string.IsNullOrEmpty(ownerName))
            {
                ModelState.AddModelError("OwnerName", "You must specify a associated owner or third party affiliate.");

                ViewData["Owners"] = owners;
                return(Page());
            }

            if (temp == false)
            {
                ModelState.AddModelError("OwnerName", "That associated owner or third party affiliate doesn't exist.");

                ViewData["Owners"] = owners;
                return(Page());
            }

            /* For version 2.0: Implement the ability to create a new affiliate when entering a name not currently in the database. Most the code is here already, we just ran out of time. CL
             * if (!owners.Contains(ownerName) && !string.IsNullOrEmpty(ownerName)) {
             *  CreateAffiliate(ownerName);
             * }
             */

            var newKey = new Key();

            if (await TryUpdateModelAsync <Key>(
                    newKey,
                    "key",
                    k => k.SerialNumber))
            {
                var user = _context.Owner.FirstOrDefault(x => x.User.UserID == HttpContext.Session.GetInt32("SessionUserID"));
                Key.LastModifiedBy     = user != null ? user.Initials : "SYS";
                Key.LastModifiedDate   = DateTime.Now;
                Key.KeyHistory.Status  = "Active";
                Key.KeyHistory.OwnerID = _context.Owner.FirstOrDefault(o => o.FullName == ownerName).OwnerID;
                _context.Key.Add(Key);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #7
0
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedContacts, int?isAdmin, string coowner = "")
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (selectedContacts[0] == null || selectedContacts[2] == null)
            {
                ModelState.AddModelError("Contacts", "You must enter both a primary phone and email.");
                await OnGetAsync(id);

                return(Page());
            }

            Models.Owner ownerToUpdate = await _context.Owner
                                         .Include(o => o.Address)
                                         .Include(o => o.OwnerContactType).ThenInclude(c => c.ContactType)
                                         .FirstOrDefaultAsync(m => m.OwnerID == id);

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

            ownerToUpdate.LastModifiedBy   = user != null ? user.Initials : "SYS";
            ownerToUpdate.LastModifiedDate = DateTime.Now;

            ownerToUpdate.IsHoaOwner = true;
            ownerToUpdate.IsPrimary  = true;

            var owners = _context.Owner.Where(x => x.IsHoaOwner == true).Select(x => x.FullName).ToList();

            if (!owners.Contains(coowner) && !string.IsNullOrEmpty(coowner))
            {
                CreateCoOwner(coowner);
            }

            ownerToUpdate.CoOwnerID = _context.Owner.FirstOrDefault(x => x.FullName == coowner)?.OwnerID;

            selectedContacts[0] = selectedContacts[0] != null?Extensions.CleanPhone(selectedContacts[0]) : null;

            selectedContacts[1] = selectedContacts[1] != null?Extensions.CleanPhone(selectedContacts[1]) : null;

            selectedContacts[3] = selectedContacts[3] != null?Extensions.CleanPhone(selectedContacts[3]) : null;

            if (await TryUpdateModelAsync <Models.Owner>(
                    ownerToUpdate, "Owner",
                    o => o.Birthday, o => o.FirstName, o => o.LastName, o => o.Address, o => o.Occupation,
                    o => o.IsPrimary, o => o.IsHoaOwner, o => o.EmergencyContactName, o => o.EmergencyContactPhone,
                    o => o.LastModifiedBy, o => o.LastModifiedDate))
            {
                if (string.IsNullOrWhiteSpace(ownerToUpdate.Address?.FullAddress))
                {
                    ownerToUpdate.Address = null;
                }
                ownerToUpdate.EmergencyContactPhone = Extensions.CleanPhone(ownerToUpdate.EmergencyContactPhone);

                var email = selectedContacts[2];        //TODO: not super safe(will break if not in expected order
                UpdateUser(ownerToUpdate.OwnerID, isAdmin, email);

                //saves address
                _context.Attach(ownerToUpdate).State = EntityState.Modified;

                UpdateOwnerContacts(_context, selectedContacts, ownerToUpdate, user);
                await _context.SaveChangesAsync();

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

            UpdateOwnerContacts(_context, selectedContacts, ownerToUpdate, user);
            PopulateAssignedOwnerContacts(_context, ownerToUpdate);
            return(Page());
        }
コード例 #8
0
        public async Task <IActionResult> OnPostAsync(string ownerName, string lotNumber)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (ownerName == null)
            {
                ModelState.AddModelError("Account", "You must specify an owner.");
                return(OnGet());
            }

            var ownerLotNumbers = _context.Lots
                                  .Where(x => x.Owner.FullName == ownerName).Select(x => x.LotNumber).ToList();

            if (!ownerLotNumbers.Contains(lotNumber) && lotNumber != null)
            {
                ModelState.AddModelError("LotNumber", "That lot does not currently belog to that owner.");
                return(OnGet());
            }

            if (string.IsNullOrEmpty(ownerName))
            {
                ModelState.AddModelError("ownerName", "You must specify a associated owner.");

                ViewData["PrivacyLevel"] = new SelectList(new List <SelectListItem>
                {
                    new SelectListItem {
                        Value = "Internal", Text = "Internal"
                    },
                    new SelectListItem {
                        Value = "Public", Text = "Public"
                    }
                }, "Value", "Text");
                ViewData["Types"]  = new SelectList(_context.HistoryType, "HistoryTypeID", "Description");
                ViewData["Lots"]   = _context.Lots.Where(x => x.IsArchive == false).Select(x => x.LotNumber).ToList();
                ViewData["Owners"] = _context.Owner.Where(x => x.IsHoaOwner == true).Select(x => x.FullName).ToList();

                return(Page());
            }

            var newOwnerHistory = new OwnerHistory();

            newOwnerHistory.OwnerID = _context.Owner.FirstOrDefault(o => o.FullName == ownerName).OwnerID;

            if (!string.IsNullOrEmpty(lotNumber))
            {
                newOwnerHistory.LotID = _context.Lots.FirstOrDefault(l => l.LotNumber == lotNumber).LotID;
            }
            else
            {
                newOwnerHistory.LotID = null;
            }

            if (await TryUpdateModelAsync <OwnerHistory>(
                    newOwnerHistory,
                    "ownerHistory",
                    o => o.HistoryTypeID, o => o.LotID, o => o.OwnerID, o => o.Date, o => o.Description, o => o.PrivacyLevel))
            {
                var user = _context.Owner.FirstOrDefault(x => x.User.UserID == HttpContext.Session.GetInt32("SessionUserID"));
                newOwnerHistory.LastModifiedBy   = user != null ? user.Initials : "SYS";
                newOwnerHistory.LastModifiedDate = DateTime.Now;

                _context.OwnerHistory.Add(newOwnerHistory);
                await _context.SaveChangesAsync();
            }
            else
            {
                return(NotFound());
            }

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