Exemplo n.º 1
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskExists(Task.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            //var sms = new CSSMS(_hostEnv, _configuration);
            //sms.SendMessage("12037700732", "Hello there Test2");

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

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

            try
            {
                if (Task != null)
                {
                    _context.Task.Remove(Task);
                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                _ = e;
            }
            return(RedirectToPage("./Index"));
        }
Exemplo n.º 3
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 4
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            //if (!ModelState.IsValid)
            //{
            //    UpdateLists();
            //    return Page();
            //}

            _context.Person.Add(_Person);
            await _context.SaveChangesAsync();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 10
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if ((_Event.Description == null) || (_Event.Description.Trim().Length == 0) || (_Event.Type <= 0))
            {
                CreateStartDate = _Event.StartTime;
                UpdateViewData("Event Type and/or Event Description must be set.");
                return(Page());
            }

            if (!ModelState.IsValid)
            {
                CreateStartDate = _Event.StartTime;
                UpdateViewData("One or more fields are not valid.");
                return(Page());
            }

            if (_Event.ChurchId == -1)
            {
                _Event.ChurchId = null;
            }

            if (_Event.StartTime >= _Event.EndTime)
            {
                CreateStartDate = _Event.StartTime;
                UpdateViewData("End Date/Time must be later than Start Date/Time.");
                return(Page());
            }

            UpdateAttendance(_Event.Id, _Event.Staff ?? 0, _Staff);

            _context.Event.Add(_Event);
            await _context.SaveChangesAsync();

            // Generate any tasks based on events
            var autogen = new AutoGen(_context);

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 11
0
        public static int RemoveChangedEventTasks(CStat.Models.CStatContext context, Event newEvent)
        {
            int NumDeleted = 0;
            var oldEvent   = context.Event.AsNoTracking().FirstOrDefaultAsync(e => e.Id == newEvent.Id).Result;

            if ((oldEvent != null) && ((newEvent.StartTime != oldEvent.StartTime) || (newEvent.EndTime != oldEvent.EndTime)))
            {
                var evTasks = context.Task.Where(t => (t.EventId.HasValue && t.EventId == newEvent.Id));
                foreach (var t in evTasks)
                {
                    try
                    {
                        context.Task.Remove(t);
                        context.SaveChangesAsync();
                        ++NumDeleted;
                    }
                    catch
                    {
                        // TBD : log these errors
                    }
                }
            }
            return(NumDeleted);
        }
Exemplo n.º 12
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if ((_Event.Description == null) || (_Event.Description.Trim().Length == 0) || (_Event.Type <= 0))
            {
                UpdateViewData("Event Type and/or Event Description must be set.");
                return(Page());
            }

            if (!ModelState.IsValid)
            {
                UpdateViewData("One or more fields are not valid.");
                return(Page());
            }

            if (_Event.ChurchId == -1)
            {
                _Event.ChurchId = null;
            }

            if (_Event.StartTime >= _Event.EndTime)
            {
                UpdateViewData("End Date/Time must be later than Start Date/Time.");
                return(Page());
            }

            // Check if Start or End Dates have changed and delete tasks associated with event and generate new ones.
            int NumTasksRemoved = RemoveChangedEventTasks(_context, _Event);

            UpdateAttendance(_Event.Id, _Event.Staff ?? 0, _Staff);

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventExists(_Event.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            if (NumTasksRemoved > 0)
            {
                // Regenerate tasks based on event now
                var autogen = new AutoGen(_context);
                autogen.GenTasks(_hostEnv);
            }

            if (string.IsNullOrEmpty(_RedirectURL))
            {
                return(RedirectToPage("./Index"));
            }
            _RedirectURL = "";
            return(NotFound());
        }
Exemplo n.º 13
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (Item.Name == "FIX_CHRS.List")
            {
                string srcFile  = Path.Combine(hostEnv.WebRootPath, "FixDB", "ChrsSrc.txt");
                string destFile = Path.Combine(hostEnv.WebRootPath, "FixDB", "ChrsList.txt");

                using (StreamReader sr = new StreamReader(srcFile))
                    using (StreamWriter sw = new StreamWriter(destFile))
                    {
                        string line;
                        while (sr.Peek() >= 0)
                        {
                            line = sr.ReadLine();
                            sw.WriteLine(line);
                            int sidx = line.IndexOf("[");
                            int eidx = line.IndexOf("]");
                            if ((sidx != -1) && (eidx != -1))
                            {
                                string[] chrsList = line.Substring(sidx, eidx - sidx).Trim().Replace("[", "").Replace("]", "").Split(',');
                                bool     isFirst  = true;
                                int      NewCID   = -1;
                                foreach (var cid in chrsList)
                                {
                                    int    id  = int.Parse(cid.Trim());
                                    Church chr = _context.Church.FirstOrDefault(p => p.Id == id);

                                    if (chr != null)
                                    {
                                        if (isFirst)
                                        {
                                            sw.WriteLine("KEY=" + id + " Name=" + chr.Name);
                                            isFirst = false;
                                            NewCID  = chr.Id;
                                        }
                                        else
                                        {
                                            sw.WriteLine(" id=" + id + " Name=" + chr.Name);

                                            // DELETE CHURCH
                                            _context.Church.Remove(chr);
                                            try
                                            {
                                                await _context.SaveChangesAsync();
                                            }
                                            catch (Exception)
                                            {
                                                sw.WriteLine("**** DB ERROR: ***** Changing person.cid. cid=[" + chr.Id + "]");
                                                return(RedirectToPage("./Index"));
                                            }

                                            //// MERGE CHURCH
                                            //var parr = _context.Person.Where(p => p.ChurchId == chr.Id).ToList<Person>();
                                            //foreach (var p in parr)
                                            //{
                                            //    p.ChurchId = NewCID;
                                            //    _context.Attach(p).State = EntityState.Modified;

                                            //    try
                                            //    {
                                            //        await _context.SaveChangesAsync();
                                            //    }
                                            //    catch (Exception e)
                                            //    {
                                            //        sw.WriteLine("**** DB ERROR: ***** Changing person.cid. cid=[" + chr.Id + "]");
                                            //        return RedirectToPage("./Index");
                                            //    }
                                            //}
                                        }
                                    }
                                    else
                                    {
                                        sw.WriteLine("**** Cant Find id [" + cid + "]");
                                    }
                                }
                            }
                            sw.WriteLine("----------------------------------------------");
                        }
                    }
            }

            if (Item.Name == "FIX_PPL.List")
            {
                string srcFile  = Path.Combine(hostEnv.WebRootPath, "FixDB", "PplSrc.txt");
                string destFile = Path.Combine(hostEnv.WebRootPath, "FixDB", "PplList.txt");

                using (StreamReader sr = new StreamReader(srcFile))
                    using (StreamWriter sw = new StreamWriter(destFile))
                    {
                        string line;
                        while (sr.Peek() >= 0)
                        {
                            line = sr.ReadLine();
                            sw.WriteLine(line);
                            int sidx = line.IndexOf("[");
                            int eidx = line.IndexOf("]");
                            if ((sidx != -1) && (eidx != -1))
                            {
                                string[] pplList = line.Substring(sidx, eidx - sidx).Trim().Replace("[", "").Replace("]", "").Split(',');
                                bool     isFirst = true;
                                int      NewPID  = -1;
                                foreach (var pid in pplList)
                                {
                                    int    id  = int.Parse(pid.Trim());
                                    Person psn = _context.Person.FirstOrDefault(p => p.Id == id);

                                    if (psn != null)
                                    {
                                        if (isFirst)
                                        {
                                            sw.WriteLine("KEY=" + id + " First=" + psn.FirstName + " Last=" + psn.LastName + " Cell=" + psn.CellPhone + " EMail=" + psn.Email);
                                            isFirst = false;
                                            NewPID  = psn.Id;
                                        }
                                        else
                                        {
                                            sw.WriteLine(" id=" + id + " First=" + psn.FirstName + " Last=" + psn.LastName + " Cell=" + psn.CellPhone + " EMail=" + psn.Email);

                                            //**** DELETE ****
                                            _context.Person.Remove(psn);
                                            try
                                            {
                                                await _context.SaveChangesAsync();
                                            }
                                            catch (Exception)
                                            {
                                                sw.WriteLine("**** DB ERROR: ***** Delete person. id=[" + psn.Id + "]");
                                            }

                                            //**** UPDATE ****
                                            //var pg1arr = _context.Person.Where(p => p.Pg1PersonId == psn.Id).ToList<Person>();
                                            //foreach (var p in pg1arr)
                                            //{
                                            //    p.Pg1PersonId = NewPID;
                                            //    _context.Attach(p).State = EntityState.Modified;

                                            //    try
                                            //    {
                                            //        await _context.SaveChangesAsync();
                                            //    }
                                            //    catch (Exception e)
                                            //    {
                                            //        sw.WriteLine("**** DB ERROR: ***** Changing PG1 pid=[" + psn.Id + "]");
                                            //        return RedirectToPage("./Index");
                                            //    }
                                            //}

                                            //var pg2arr = _context.Person.Where(p => p.Pg2PersonId == psn.Id).ToList<Person>();
                                            //foreach (var p in pg2arr)
                                            //{
                                            //    p.Pg2PersonId = NewPID;
                                            //    _context.Attach(p).State = EntityState.Modified;

                                            //    try
                                            //    {
                                            //        await _context.SaveChangesAsync();
                                            //    }
                                            //    catch (Exception e)
                                            //    {
                                            //        sw.WriteLine("**** DB ERROR: ***** Changing PG2 pid=[" + psn.Id + "]");
                                            //        return RedirectToPage("./Index");
                                            //    }
                                            //}

                                            //var attarr = _context.Attendance.Where(a => a.PersonId == psn.Id).ToList<Attendance>();
                                            //foreach (var a in attarr)
                                            //{
                                            //    a.PersonId = NewPID;
                                            //    _context.Attach(a).State = EntityState.Modified;

                                            //    try
                                            //    {
                                            //        await _context.SaveChangesAsync();
                                            //    }
                                            //    catch (Exception e)
                                            //    {
                                            //        sw.WriteLine("**** DB ERROR: ***** Changing Attendance pid=[" + psn.Id + "]");
                                            //        return RedirectToPage("./Index");
                                            //    }
                                            //}
                                        }
                                    }
                                    else
                                    {
                                        sw.WriteLine("**** Cant Find id [" + pid + "]");
                                    }
                                }
                            }
                            sw.WriteLine("----------------------------------------------");
                        }
                    }
            }

            if (Item.Name == "FIX_ADRS.List")
            {
                string srcFile  = Path.Combine(hostEnv.WebRootPath, "FixDB", "AdrSrc.txt");
                string destFile = Path.Combine(hostEnv.WebRootPath, "FixDB", "AdrList.txt");

                using (StreamReader sr = new StreamReader(srcFile))
                    using (StreamWriter sw = new StreamWriter(destFile))
                    {
                        string line;
                        while (sr.Peek() >= 0)
                        {
                            line = sr.ReadLine();
                            sw.WriteLine(line);
                            int idx = line.IndexOf("[");
                            if (idx != -1)
                            {
                                string[] adrList  = line.Substring(idx).Trim().Replace("[", "").Replace("]", "").Split(',');
                                bool     isFirst  = true;
                                int      NewAdrID = -1;
                                foreach (var aid in adrList)
                                {
                                    int     id  = int.Parse(aid.Trim());
                                    Address adr = _context.Address.FirstOrDefault(a => a.Id == id);

                                    if (adr != null)
                                    {
                                        if (isFirst)
                                        {
                                            sw.WriteLine("KEY=" + id + " Street=" + adr.Street + " Town=" + adr.Town + " State=" + adr.State + " Zip=" + adr.ZipCode);
                                            isFirst  = false;
                                            NewAdrID = adr.Id;
                                        }
                                        else
                                        {
                                            sw.WriteLine(" id=" + id + " Street=" + adr.Street + " Town=" + adr.Town + " State=" + adr.State + " Zip=" + adr.ZipCode);

                                            _context.Address.Remove(adr);
                                            try
                                            {
                                                await _context.SaveChangesAsync();
                                            }
                                            catch (Exception)
                                            {
                                                sw.WriteLine("**** DB ERROR: ***** Changing person.aid. aid=[" + adr.Id + "]");
                                                return(RedirectToPage("./Index"));
                                            }

                                            //var parr = _context.Person.Where(p => p.AddressId == adr.Id).ToList<Person>();
                                            //foreach (var p in parr)
                                            //{
                                            //    p.AddressId = NewAdrID;
                                            //    _context.Attach(p).State = EntityState.Modified;

                                            //    try
                                            //    {
                                            //        await _context.SaveChangesAsync();
                                            //    }
                                            //    catch (Exception e)
                                            //    {
                                            //        sw.WriteLine("**** DB ERROR: ***** Changing person.aid. aid=[" + adr.Id + "]");
                                            //        return RedirectToPage("./Index");
                                            //    }
                                            //}

                                            //var carr = _context.Church.Where(c => c.AddressId == adr.Id).ToList<Church>();
                                            //foreach (var c in carr)
                                            //{
                                            //    c.AddressId = NewAdrID;
                                            //    _context.Attach(c).State = EntityState.Modified;

                                            //    try
                                            //    {
                                            //        await _context.SaveChangesAsync();
                                            //    }
                                            //    catch
                                            //    {
                                            //        sw.WriteLine("**** DB ERROR: ***** Changing church.aid. aid=[" + adr.Id + "]");
                                            //        return RedirectToPage("./Index");
                                            //    }
                                            //}
                                        }
                                    }
                                    else
                                    {
                                        sw.WriteLine("**** Cant Find id [" + aid + "]");
                                    }
                                }
                            }
                            sw.WriteLine("----------------------------------------------");
                        }
                    }
            }


            if (Item.Name == "ALL_ITEMS")
            {
                //Item itemA = new Item();
                //itemA.Name = "AAA";
                //itemA.Size = 1;
                //itemA.Units = 1;
                //itemA.Status = 1;
                //itemA.Upc = "111";
                //_context.Item.Add(itemA);
                //int resA = await _context.SaveChangesAsync();

                //InventoryItem invItemA = new InventoryItem();
                //invItemA.ItemId = itemA.Id;
                //invItemA.InventoryId = 1;
                //invItemA.ReorderThreshold = (float)10;
                //invItemA.Units = itemA.Units;
                //_context.InventoryItem.Add(invItemA);
                //int resA2 = await _context.SaveChangesAsync();

                //Item itemB = new Item();
                //itemB.Name = "BBB";
                //itemB.Size = 1;
                //itemB.Units = 2;
                //itemB.Status = 1;
                //itemB.Upc = "222";
                //_context.Item.Add(itemB);
                //int resB = await _context.SaveChangesAsync();

                //InventoryItem invItemB = new InventoryItem();
                //invItemB.ItemId = itemB.Id;
                //invItemB.InventoryId = 1;
                //invItemB.ReorderThreshold = (float)20;
                //invItemB.Units = itemB.Units;
                //_context.InventoryItem.Add(invItemB);
                //int resB2 = await _context.SaveChangesAsync();

                //Console.WriteLine(resA + "," + resA2 + "," + resB + "," + resB2);

                // Add all items and Inventory Items

                //Inventory inv = new Inventory();
                //inv.Id = 1;
                //inv.Name = "Non-Edible";
                //inv.Type = 1;
                //_context.Inventory.Add(inv);
                //await _context.SaveChangesAsync();

                foreach (var str in ItemDataStrings)
                {
                    ItemData idobj = JsonConvert.DeserializeObject <ItemData>(str);

                    Item item = new Item();
                    item.Name = idobj.name.Replace("^^", "\"").Replace("^", "'");
                    item.Size = 1;
                    ItemUnits units;
                    if (ItemUnits.TryParse(idobj.units, out units))
                    {
                        item.Units = (int)units;
                    }
                    else
                    {
                        item.Units = (int)ItemUnits.unknown;
                    }
                    item.Status = 1;
                    item.Upc    = "";

                    _context.Item.Add(item);
                    int res1 = await _context.SaveChangesAsync();

                    InventoryItem invItem = new InventoryItem();
                    invItem.ItemId           = item.Id;
                    invItem.InventoryId      = 1;
                    invItem.ReorderThreshold = (float)idobj.reorder;
                    invItem.Units            = item.Units;
                    _context.InventoryItem.Add(invItem);
                    int res2 = await _context.SaveChangesAsync();
                }
            }

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


            return(RedirectToPage("./Index"));
        }
Exemplo n.º 14
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Page());
                }
                Address adr = new Address();
                adr.Street  = _Street;
                adr.Town    = _Town;
                adr.ZipCode = _ZipCode;
                adr.Phone   = _Phone;
                adr.State   = _State;
                adr.Fax     = _Fax;
                adr.Country = "USA";

                if (!string.IsNullOrEmpty(adr.Phone) || !string.IsNullOrEmpty(adr.Fax))
                {
                    if (!AddressMgr.Validate(ref adr))
                    {
                        if (string.IsNullOrEmpty(adr.Street))
                        {
                            adr.Street = "<missing>";
                        }
                        if (string.IsNullOrEmpty(adr.Town))
                        {
                            adr.Town = "<missing>";
                        }
                        if (string.IsNullOrEmpty(adr.State))
                        {
                            adr.State = "NY";
                        }
                        if (string.IsNullOrEmpty(adr.ZipCode))
                        {
                            adr.ZipCode = "11111";
                        }
                    }
                }

                int?id = Address.UpdateAddress(_context, adr);
                if (id.HasValue && (id.Value > 0))
                {
                    Business.AddressId = id;
                    Business.Address   = null;
                }
                else
                {
                    Business.AddressId = null;
                    Business.Address   = null;
                }

                Business.PocId = !string.IsNullOrEmpty(_poc) ? Person.PersonIdFromExactName(_context, _poc) : null;
                if (!string.IsNullOrEmpty(Business.UserLink))
                {
                    Business.UserLink = Business.UserLink.Trim();
                }
                _context.Business.Add(Business);
                await _context.SaveChangesAsync();
            }
            catch
            { }
            return(RedirectToPage("./Index"));
        }
Exemplo n.º 15
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (string.IsNullOrEmpty(_Business.Name) || (_Business.Type == (int)Business.EType.Unknown))
            {
                return(Page());
            }

            if (!string.IsNullOrEmpty(_ZipCode))
            {
                _ZipCode = Address.StripZip(_ZipCode);
            }

            Address adr = new Address();

            adr.Street  = _Street;
            adr.Town    = _Town;
            adr.ZipCode = _ZipCode;
            adr.Phone   = _Phone;
            adr.State   = _State;
            adr.Fax     = _Fax;
            adr.Country = "USA";

            if (!string.IsNullOrEmpty(adr.Phone) || !string.IsNullOrEmpty(adr.Fax))
            {
                if (!AddressMgr.Validate(ref adr))
                {
                    if (string.IsNullOrEmpty(adr.Street))
                    {
                        adr.Street = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.Town))
                    {
                        adr.Town = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.State))
                    {
                        adr.State = "NY";
                    }
                    if (string.IsNullOrEmpty(adr.ZipCode))
                    {
                        adr.ZipCode = "11111";
                    }
                }
            }

            int?id = Address.UpdateAddress(_context, adr);

            if (id.HasValue && (id.Value > 0))
            {
                _Business.AddressId = id;
                _Business.Address   = null;
            }
            else
            {
                _Business.AddressId = null;
                _Business.Address   = null;
            }
            _Business.PocId = !string.IsNullOrEmpty(_poc) ? Person.PersonIdFromExactName(_context, _poc) : null;
            if (!string.IsNullOrEmpty(_Business.UserLink))
            {
                _Business.UserLink = _Business.UserLink.Trim();
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BusinessExists(_Business.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            if (string.IsNullOrEmpty(_RedirectURL))
            {
                return(RedirectToPage("./Index"));
            }
            _RedirectURL = "";
            return(NotFound());
        }
Exemplo n.º 16
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Address adr = new Address();

            adr.Street  = _Street;
            adr.Town    = _Town;
            adr.ZipCode = _ZipCode;
            adr.Phone   = _Phone;
            adr.State   = _State;
            adr.Fax     = _Fax;
            adr.Country = "USA";

            if (!string.IsNullOrEmpty(adr.Phone) || !string.IsNullOrEmpty(adr.Fax))
            {
                if (!AddressMgr.Validate(ref adr))
                {
                    if (string.IsNullOrEmpty(adr.Street))
                    {
                        adr.Street = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.Town))
                    {
                        adr.Town = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.State))
                    {
                        adr.State = "NY";
                    }
                    if (string.IsNullOrEmpty(adr.ZipCode))
                    {
                        adr.ZipCode = "11111";
                    }
                }
            }

            int?id = Address.UpdateAddress(_context, adr);

            if (id.HasValue && (id.Value > 0))
            {
                Church.AddressId = id;
                Church.Address   = null;
            }
            else
            {
                Church.AddressId = null;
                Church.Address   = null;
            }

            Church.SeniorMinisterId = Person.PersonIdFromExactName(_context, _SeniorMinister);
            Church.YouthMinisterId  = Person.PersonIdFromExactName(_context, _YouthMinister);
            Church.Trustee1Id       = Person.PersonIdFromExactName(_context, _Trustee1);
            Church.Trustee2Id       = Person.PersonIdFromExactName(_context, _Trustee2);
            Church.Trustee3Id       = Person.PersonIdFromExactName(_context, _Trustee3);
            Church.Alternate1Id     = Person.PersonIdFromExactName(_context, _Alternate1);
            Church.Alternate2Id     = Person.PersonIdFromExactName(_context, _Alternate2);
            Church.Alternate3Id     = Person.PersonIdFromExactName(_context, _Alternate3);

            if (int.TryParse(Church.Affiliation, out int affIdx))
            {
                Church.Affiliation = ((AffiliationType)affIdx).ToString();
            }
            else
            {
                Church.Affiliation = AffiliationType.UNK.ToString();
            }

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

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 17
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!InventoryItem.Units.HasValue || (EditItem.Size <= 0))
            {
                ViewData["ItemErrors"] = "* Must have a non-zero Units/Item.";
                return(Page());
            }

            if (InventoryItem.ReorderThreshold.HasValue && (InventoryItem.ReorderThreshold.Value <= 0))
            {
                InventoryItem.ReorderThreshold = null;
            }

            if (InventoryItem.UnitsPerDay.HasValue && (InventoryItem.UnitsPerDay.Value <= 0))
            {
                InventoryItem.UnitsPerDay = null;
            }

            if (ItemPhoto != null)
            {
                if ((EditItem.Upc == null) || (EditItem.Upc.Trim().Length == 0))
                {
                    ViewData["UPCError"] = "Error : UPC Must be specified with Photo.";
                    return(Page());
                }
                string destFile = Path.Combine(hostEnv.WebRootPath, "items", "ItmImg_" + EditItem.Upc + ".jpg");

                if (System.IO.File.Exists(destFile))
                {
                    System.IO.File.Delete(destFile); // Delete any existing photo for this item
                }
                using (var fs = new FileStream(destFile, FileMode.Create))
                {
                    ItemPhoto.CopyTo(fs);
                }
            }

            if ((EditItem.Name != null) && (EditItem.Name.Length > 0))
            {
                EditItem.Name.Trim();
            }
            if ((EditItem.Upc != null) && (EditItem.Upc.Length > 0))
            {
                EditItem.Upc.Trim();
            }

            List <int?> tidsToDel = new List <int?>();

            tidsToDel.Add(GetBuyTransaction(1, Buy1URL));
            tidsToDel.Add(GetBuyTransaction(2, Buy2URL));
            tidsToDel.Add(GetBuyTransaction(3, Buy3URL));

            _context.Attach(InventoryItem).State = EntityState.Modified;
            _context.Attach(EditItem).State      = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _ = ex;
            }

            // Try to delete unused transactions AFTER updating InventoryItem
            foreach (var tid in tidsToDel)
            {
                try
                {
                    if (tid.HasValue)
                    {
                        var OldTrans = _context.Transaction.Find(tid.Value);
                        if (OldTrans != null)
                        {
                            _context.Transaction.Remove(OldTrans);
                            _context.SaveChanges();
                        }
                    }
                }
                catch { }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!InventoryItem.Units.HasValue || (CreateItem.Size <= 0))
            {
                ViewData["ItemErrors"] = "* Must have a non-zero Units/Item.";
                return(Page());
            }

            if (InventoryItem.ReorderThreshold.HasValue && (InventoryItem.ReorderThreshold.Value <= 0))
            {
                InventoryItem.ReorderThreshold = null;
            }

            if (InventoryItem.UnitsPerDay.HasValue && (InventoryItem.UnitsPerDay.Value <= 0))
            {
                InventoryItem.UnitsPerDay = null;
            }

            if ((CreateItem.Name != null) && (CreateItem.Name.Length > 0))
            {
                CreateItem.Name.Trim();
            }

            if ((CreateItem.Upc != null) && (CreateItem.Upc.Length > 0))
            {
                CreateItem.Upc.Trim();
            }

            if (ItemPhoto != null)
            {
                if ((CreateItem.Upc == null) || (CreateItem.Upc.Trim().Length == 0))
                {
                    ViewData["UPCError"] = "Error : UPC Must be specified with Photo.";
                    return(Page());
                }
                string destFile = Path.Combine(hostEnv.WebRootPath, "items", "ItmImg_" + CreateItem.Upc + ".jpg");

                if (System.IO.File.Exists(destFile))
                {
                    System.IO.File.Delete(destFile); // Delete any existing photo for this item
                }
                using (var fs = new FileStream(destFile, FileMode.Create))
                {
                    ItemPhoto.CopyTo(fs);
                }
            }

            GetBuyTransaction(1, Buy1URL);
            GetBuyTransaction(2, Buy2URL);
            GetBuyTransaction(3, Buy3URL);

            try
            {
                CreateItem.Units = InventoryItem.Units.HasValue ? InventoryItem.Units.Value : (int)InventoryItem.ItemZone.unknown;
                _context.Item.Add(CreateItem);
                int res1 = await _context.SaveChangesAsync();

                InventoryItem.ItemId      = CreateItem.Id;
                InventoryItem.InventoryId = 1;
                _context.InventoryItem.Add(InventoryItem);
                int res2 = await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                String err = e.Message;
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 19
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            //if (!ModelState.IsValid)
            //{
            //    return Page();
            //}

            Address adr = new Address();

            adr.Street  = _Street;
            adr.Town    = _Town;
            adr.ZipCode = _ZipCode;
            adr.Phone   = _Phone;
            adr.State   = _State;
            adr.Fax     = _Fax;
            adr.Country = "USA";

            if (!string.IsNullOrEmpty(adr.Phone) || !string.IsNullOrEmpty(adr.Fax))
            {
                if (!AddressMgr.Validate(ref adr))
                {
                    if (string.IsNullOrEmpty(adr.Street))
                    {
                        adr.Street = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.Town))
                    {
                        adr.Town = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.State))
                    {
                        adr.State = "NY";
                    }
                    if (string.IsNullOrEmpty(adr.ZipCode))
                    {
                        adr.ZipCode = "11111";
                    }
                }
            }

            int?id = Address.UpdateAddress(_context, adr);

            if (id.HasValue && (id.Value > 0))
            {
                _Church.AddressId = id;
                _Church.Address   = null;
            }
            else
            {
                _Church.AddressId = null;
                _Church.Address   = null;
            }

            if (!_Church.SeniorMinisterId.HasValue)
            {
                _Church.SeniorMinisterId = Person.PersonIdFromExactName(_context, _SeniorMinister);
            }
            if (!_Church.YouthMinisterId.HasValue)
            {
                _Church.YouthMinisterId = Person.PersonIdFromExactName(_context, _YouthMinister);
            }
            if (!_Church.Trustee1Id.HasValue)
            {
                _Church.Trustee1Id = Person.PersonIdFromExactName(_context, _Trustee1);
            }
            if (!_Church.Trustee2Id.HasValue)
            {
                _Church.Trustee2Id = Person.PersonIdFromExactName(_context, _Trustee2);
            }
            if (!_Church.Trustee3Id.HasValue)
            {
                _Church.Trustee3Id = Person.PersonIdFromExactName(_context, _Trustee3);
            }
            if (!_Church.Alternate1Id.HasValue)
            {
                _Church.Alternate1Id = Person.PersonIdFromExactName(_context, _Alternate1);
            }
            if (!_Church.Alternate2Id.HasValue)
            {
                _Church.Alternate2Id = Person.PersonIdFromExactName(_context, _Alternate2);
            }
            if (!_Church.Alternate3Id.HasValue)
            {
                _Church.Alternate3Id = Person.PersonIdFromExactName(_context, _Alternate3);
            }

            _Church.Affiliation = ((AffiliationType)_Affiliation).ToString();

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
            }

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