public ActionResult Create([Bind(Include = "Remarks, EventID, VolunteerID")] Volunteering volunteering)
        {
            bool b = true;

            //assign datetime from event
            Event evt = db.Events.Find(volunteering.EventID);

            volunteering.BeginDate = evt.StartDate;
            volunteering.BeginTime = evt.StartTime;
            volunteering.EndDate   = evt.EndDate;
            volunteering.EndTime   = evt.EndTime;

            //check for datetime conflicts as required!
            //check for datetime conflicts as required!
            //check for datetime conflicts as required!
            //check for datetime conflicts as required!
            foreach (Volunteering vs in db.Volunteerings
                     .Where(el => (el.VolunteerID == volunteering.VolunteerID)))
            {
                DateTime startDate        = new DateTime(vs.BeginDate.Year, vs.BeginDate.Month, vs.BeginDate.Day, vs.BeginTime.Hour, vs.BeginTime.Minute, vs.BeginTime.Second);
                DateTime endDate          = new DateTime(vs.EndDate.Year, vs.EndDate.Month, vs.EndDate.Day, vs.EndTime.Hour, vs.EndTime.Minute, vs.EndTime.Second);
                DateTime startCompareDate = new DateTime(volunteering.BeginDate.Year, volunteering.BeginDate.Month, volunteering.BeginDate.Day, volunteering.BeginTime.Hour, volunteering.BeginTime.Minute, volunteering.BeginTime.Second);
                DateTime endCompareDate   = new DateTime(volunteering.EndDate.Year, volunteering.EndDate.Month, volunteering.EndDate.Day, volunteering.EndTime.Hour, volunteering.EndTime.Minute, volunteering.EndTime.Second);
                if ((startCompareDate >= startDate && startCompareDate <= endDate)
                    ||
                    (endCompareDate >= startDate && endCompareDate <= endDate))
                {
                    b = false;
                }
            }

            if (!b)
            {
                TempData["ErrorMessage"] = "This Volunteer has already been assigned to another event within this time slot.";
                return(RedirectToAction("Index"));
            }

            //duplicates
            if (db.Volunteerings.Where(el => (el.VolunteerID == volunteering.VolunteerID)
                                       &&
                                       (el.EventID == volunteering.EventID)).Count() > 0)
            {
                TempData["ErrorMessage"] = "The Volunteer has already been assigned to the Event.";
                return(RedirectToAction("Index"));
            }

            if (ModelState.IsValid)
            {
                db.Volunteerings.Add(volunteering);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.EventID     = new SelectList(db.Events, "EventID", "Title", volunteering.EventID);
            ViewBag.VolunteerID = new SelectList(db.Volunteers, "VolunteerID", "FirstName", volunteering.VolunteerID);
            return(View(volunteering));
        }
        public static bool doRemoveCartItem(int CartItemID)
        {
            Guid testId;
            bool t = false;

            if ((Guid.TryParse(Generics.IfNullString(Default.AppUserUniqueKey), out testId)) && (CartItemID > 0))
            {
                SrvContext dbCtx      = new SrvContext();
                int        CustomerID = dbCtx.Customers
                                        .Where(el => (el.UniqueKey == testId))
                                        .Single()
                                        .CustomerID;
                if (dbCtx.CartItems.Where(el => (el.CartItemID == CartItemID)
                                          &&
                                          (el.CustomerID == CustomerID)).Count() == 1)
                {
                    CartItem ci = dbCtx.CartItems
                                  .Where(el => (el.CartItemID == CartItemID)
                                         &&
                                         (el.CustomerID == CustomerID))
                                  .Single();
                    dbCtx.CartItems.Remove(ci);
                    try
                    {
                        t = (dbCtx.SaveChanges() > 0);
                    }
                    catch
                    {
                        ;
                    }
                }
            }
            return(t);
        }
Exemple #3
0
 public ActionResult Edit([Bind(Include = "VolunteerID, FirstName, LastName, Username, Phone, DateOfBirth, IsFemale, Address, City, State, Zip, IsActive")] Volunteer volunteer)
 {
     //if (ModelState.IsValid)
     {
         if (volunteer.VolunteerID > 0)
         {
             db.Entry(volunteer).State = EntityState.Modified;
         }
         else
         {
             db.Volunteers.Add(volunteer);
         }
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     //return View(volunteer);
 }
        public static bool doUpdateCartItemQuantity(int CartItemID, byte quantity)
        {
            Guid testId;
            bool t = false;

            if (Guid.TryParse(Generics.IfNullString(Default.AppUserUniqueKey), out testId))
            {
                SrvContext dbCtx = new SrvContext();
                Customer   cx    = dbCtx.Customers
                                   .Where(el => (el.UniqueKey == testId))
                                   .Single();
                CartItem ci;
                if (dbCtx.CartItems
                    .Where(el => (el.CustomerID == cx.CustomerID)
                           &&
                           el.IsActive
                           &&
                           (el.CartItemID == CartItemID)).Count() == 1)
                {
                    ci = dbCtx.CartItems
                         .Where(el => (el.CustomerID == cx.CustomerID)
                                &&
                                el.IsActive
                                &&
                                (el.CartItemID == CartItemID))
                         .Single();
                    if ((ci.Quantity > 0) && (ci.Quantity < 10))
                    {
                        ci.Quantity  = quantity;
                        ci.ItemPrice = double.Parse(Generics.IfNullString(dbCtx.Products
                                                                          .Where(el => (el.ProductID == ci.ProductID))
                                                                          .Single()
                                                                          .UnitPrice)) * ci.Quantity;
                        if (Validator.TryValidateObject(ci,
                                                        new ValidationContext(ci, serviceProvider: null, items: null),
                                                        new List <ValidationResult>(),
                                                        true))
                        {
                            try
                            {
                                t = (dbCtx.SaveChanges() > 0);
                            }
                            catch
                            {
                                ;
                            }
                        }
                    }
                }
            }
            return(t);
        }
 public ActionResult Edit([Bind(Include = "EventID, StartDate, EndDate, Title, Description, Capacity, VolunteersRequired, VenueAddress, VenueCity, VenueState, VenueZip, VenuePhone, IsActive")] Event @event)
 {
     //if (ModelState.IsValid)
     {
         string StartTime    = string.Empty;
         string EndTime      = string.Empty;
         int    startHour    = 0;
         int    startMinutes = 0;
         int    endHour      = 0;
         int    endMinutes   = 0;
         StartTime        = Request.Form["StartTime"];
         EndTime          = Request.Form["EndTime"];
         startHour        = int.Parse(StartTime.Split(':')[0]);
         startMinutes     = int.Parse(StartTime.Split(':')[1]);
         endHour          = int.Parse(EndTime.Split(':')[0]);
         endMinutes       = int.Parse(EndTime.Split(':')[1]);
         @event.StartTime = (new DateTime(1999, 12, 31, startHour, startMinutes, 0));
         @event.EndTime   = (new DateTime(1999, 12, 31, endHour, endMinutes, 0));
         if (@event.EventID > 0)
         {
             //Event dEvent = db.Events.Find(@event.EventID);
             //@event.StartDate = dEvent.StartDate;
             //@event.StartTime = dEvent.StartTime;
             //@event.EndDate = dEvent.EndDate;
             //@event.EndTime = dEvent.EndTime;
             //dEvent = null;
             db.Entry(@event).State = EntityState.Modified;
         }
         else
         {
             db.Events.Add(@event);
         }
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     //return View(volunteer);
 }
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            bool     t           = false;
            Customer newCustomer = new Customer();

            newCustomer.FirstName   = txtRegisterFirstName.Text;
            newCustomer.LastName    = txtRegisterLastName.Text;
            newCustomer.Username    = txtRegisterUsername.Text;
            newCustomer.Phone       = decimal.Parse(txtRegisterPhone.Text);
            newCustomer.PasswordBin = Generics.MakeHash(txtRegisterPassword.Text);
            if (Validator.TryValidateObject(newCustomer,
                                            new ValidationContext(newCustomer, serviceProvider: null, items: null),
                                            new List <ValidationResult>(),
                                            true))
            {
                dbCtx.Customers.Add(newCustomer);
                try
                {
                    if (dbCtx.SaveChanges() > 0)
                    {
                        lblRegistrationSummary.Text     = "You have been successfully registered into the system.";
                        lblRegistrationSummary.CssClass = lblRegistrationSummary.CssClass.Replace("warning", "success");
                        lblRegistrationSummary.CssClass = lblRegistrationSummary.CssClass.Replace("red", "green");
                        lblRegistrationSummary.Visible  = true;
                        t = true;
                    }
                }
                catch
                {
                    lblRegistrationSummary.Text = "A user with the Email Address or Phone Number already exists in the system.";
                }
            }

            if (!t)
            {
                lblRegistrationSummary.Visible = true;
            }
        }
Exemple #7
0
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            Order o = new Order();
            bool  t = false;

            o.CustomerID = dbCtx.Customers
                           .Where(el => (el.UniqueKey == testId))
                           .Single()
                           .CustomerID;
            o.UniqueOrderNumber = Guid.NewGuid();
            o.OrderDate         = DateTime.Now;
            o.FirstName         = txtMFirstName.Text;
            o.LastName          = txtMLastName.Text;
            o.BillingAddress    = txtMBillingAddress.Text;
            o.BillingCity       = txtMBillingCity.Text;
            o.BillingState      = txtMBillingCity.Text;
            o.BillingZip        = int.Parse(txtMBillingZip.Text);
            if (chkMShippingIsSame.Checked)
            {
                o.ShippingAddress = o.BillingAddress;
                o.ShippingCity    = o.BillingCity;
                o.ShippingState   = o.BillingState;
                o.ShippingZip     = o.BillingZip;
            }
            else
            {
                o.ShippingAddress = txtMShippingAddress.Text;
                o.ShippingCity    = txtMShippingCity.Text;
                o.ShippingState   = txtMShippingCity.Text;
                o.ShippingZip     = int.Parse(txtMShippingZip.Text);
            }
            o.TaxSum    = TotalTax;
            o.TotalSum  = TotalOrderAmount;
            o.Notes     = txtNotes.Text;
            o.IsOrdered = true;
            if (Validator.TryValidateObject(o,
                                            new ValidationContext(o, serviceProvider: null, items: null),
                                            new List <ValidationResult>(),
                                            true))
            {
                dbCtx.Orders.Add(o);
                try
                {
                    int OrderId = dbCtx.SaveChanges();
                    if (OrderId > 0)
                    {
                        foreach (CartItem ci in dbCtx.CartItems
                                 .Where(el => (el.CustomerID == o.CustomerID)
                                        &&
                                        el.IsActive))
                        {
                            ci.OrderID  = OrderId;
                            ci.IsActive = false;
                        }
                        dbCtx.SaveChanges();
                        lblOrderSummary.Text     = ("Your order was successfully placed. Please note that your Order# is " + o.UniqueOrderNumber + ".");
                        lblOrderSummary.CssClass = lblOrderSummary.CssClass.Replace("warning", "success");
                        lblOrderSummary.CssClass = lblOrderSummary.CssClass.Replace("red", "green");
                        pnlOrder.Visible         = false;
                        lblOrderSummary.Visible  = true;
                        t = true;
                    }
                }
                catch
                {
                    lblOrderSummary.Text = "There was an error placing your order.";
                }
            }

            if (!t)
            {
                lblOrderSummary.Visible = true;
            }
        }
Exemple #8
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            bool t = false;

            if (updCustomer != null)
            {
                updCustomer.FirstName      = txtMFirstName.Text;
                updCustomer.LastName       = txtMLastName.Text;
                updCustomer.BillingAddress = txtMBillingAddress.Text;
                updCustomer.BillingCity    = txtMBillingCity.Text;
                updCustomer.BillingState   = txtMBillingState.Text;
                if (Generics.IfNullString(txtMBillingZip.Text).Length == 5)
                {
                    updCustomer.BillingZip = int.Parse(txtMBillingZip.Text);
                }

                if (chkMShippingIsSame.Checked)
                {
                    updCustomer.ShippingAddress = updCustomer.BillingAddress;
                    updCustomer.ShippingCity    = updCustomer.BillingCity;
                    updCustomer.ShippingState   = updCustomer.BillingState;
                    updCustomer.ShippingZip     = updCustomer.BillingZip;
                }
                else
                {
                    updCustomer.ShippingAddress = txtMShippingAddress.Text;
                    updCustomer.ShippingCity    = txtMShippingCity.Text;
                    updCustomer.ShippingState   = txtMShippingState.Text;
                    if (Generics.IfNullString(txtMShippingZip.Text).Length == 5)
                    {
                        updCustomer.ShippingZip = int.Parse(txtMShippingZip.Text);
                    }
                }

                if (Validator.TryValidateObject(updCustomer,
                                                new ValidationContext(updCustomer, serviceProvider: null, items: null),
                                                new List <ValidationResult>(),
                                                true))
                {
                    try
                    {
                        //SrvContext dbCtx = new SrvContext();
                        if (dbCtx.SaveChanges() > 0)
                        {
                            lblUpdateSummary.Text     = "Your details have successfully been updated in the system.";
                            lblUpdateSummary.CssClass = lblUpdateSummary.CssClass.Replace("warning", "success");
                            lblUpdateSummary.CssClass = lblUpdateSummary.CssClass.Replace("red", "green");
                            lblUpdateSummary.Visible  = true;
                            t = true;
                        }
                    }
                    catch
                    {
                        lblUpdateSummary.Text = "There was an error updating your information in the system.";
                    }
                }
            }
            if (!t)
            {
                lblUpdateSummary.Visible = true;
            }
        }