public ActionResult Index(string searchBy, string search)
        {
            //List<Event> events = db.Events.ToList();

            //db.Events.Remove(events[0]);
            //db.SaveChanges();
            try
            {
                foreach (ServiceRequest item in db.ServiceRequests.ToList())
                {
                    Event items = db.Events.Find(item.ServiceRequestID);
                    db.Events.Remove(items);
                    db.SaveChanges();
                }
            }
            catch
            {
            }

            if (searchBy == "Location")
            {
                return(View(db.ServiceRequests.Where(x => x.Location.StreetAddress.StartsWith(search) || search == null).ToList()));
            }
            else
            {
                return(View(db.ServiceRequests.Where(x => x.ServiceRequestStatu.Description.StartsWith(search) || search == null).ToList()));
            }
            // return View(db.ServiceRequests.Where(x => x.ServiceRequestStatu.Description.ToString().StartsWith(search) || search == null).ToList());
            //return View();
        }
Пример #2
0
        //public ActionResult AddDate()
        //{
        //    ServiceRequest dates = db.ServiceRequests.FirstOrDefault(x => x.ServiceRequestID == main);

        //    try
        //    {
        //        Event e = new Event();
        //        e.EventID = dates.ServiceRequestID;
        //        e.Start = dates.ServiceBookedDate;
        //        e.End = dates.ServiceBookedEndDate;
        //        e.Subject = dates.Location.City;
        //        e.IsFullDay = true;
        //        db.Events.Add(e);

        //        db.SaveChanges();
        //    }
        //    catch
        //    {

        //    }
        //    return View("AddService");

        //}
        public ActionResult ServiceRequest(int?id)
        {
            db.Events.ToList().Clear();
            db.SaveChanges();
            Event obj = new Event();

            return(View());
        }
Пример #3
0
        public ActionResult CancelOrder(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;
            ProductOrder po = db.ProductOrders.Where(p => p.ProductOrderID == id).FirstOrDefault();

            po.ProductOrderStatusID = 9;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
 public ActionResult Index(string searchBy, string search)
 {
     v.DateAccessed   = DateTime.Now;
     v.TableAccessed  = "Product Type";
     v.ChangesMade    = "Viewed Product Types Table";
     v.AuditLogTypeID = 1;
     //v.UserID = eqp.user.UserID;
     db.AuditLogs.Add(v);
     db.SaveChanges();
     return(View(db.ProductTypes.Where(x => x.Description.StartsWith(search) || search == null).ToList()));
 }
Пример #5
0
        public ActionResult ForgotPassword(string EmailID)
        {
            //Verify Email ID
            //Generate Reset password link
            //Send Email
            string message = "";
            bool   status  = false;

            using (SpartanFireDBEntities1 dc = new SpartanFireDBEntities1())
            {
                var account = dc.Users.Where(a => a.UserEmail == EmailID).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.UserEmail, resetCode, "ResetPassword");
                    //account.ResetPasswordCode = resetCode;
                    //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property
                    //in our model class in part 1
                    dc.Configuration.ValidateOnSaveEnabled = false;
                    dc.SaveChanges();
                    message = "Reset password link has been sent to your email id.";
                }
                else
                {
                    message = "Account not found";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
Пример #6
0
 public ActionResult Index(string searchBy, string search)
 {
     v.DateAccessed   = DateTime.Now;
     v.TableAccessed  = "Vehicle";
     v.ChangesMade    = "Viewed Vehicles Table";
     v.AuditLogTypeID = 1;
     //v.UserID = eqp.user.UserID;
     db.AuditLogs.Add(v);
     db.SaveChanges();
     if (searchBy == "Description")
     {
         return(View(db.Vehicles.Where(x => x.Description.StartsWith(search) || search == null).ToList()));
     }
     else
     {
         return(View(db.Vehicles.Where(x => x.LicenseNumber.StartsWith(search) || search == null).ToList()));
     }
 }
Пример #7
0
        public ActionResult Assign(int DelID, int employee)
        {
            db.Configuration.ProxyCreationEnabled = false;
            AssignDelivery ad = new AssignDelivery();

            ad.DeliveryID = DelID;
            ad.EmployeeID = employee;
            db.AssignDeliveries.Add(ad);
            db.SaveChanges();
            return(RedirectToAction("AssignDelivery", "Delivery", new { id = DelID }));
        }
Пример #8
0
        public ActionResult Index(string searchBy, string search)
        {
            v.DateAccessed   = DateTime.Now;
            v.TableAccessed  = "Employee";
            v.ChangesMade    = "Viewed Employees Table";
            v.AuditLogTypeID = 1;
            //v.UserID = eqp.user.UserID;
            db.AuditLogs.Add(v);
            db.SaveChanges();
            Employee cust = new Employee();

            if (searchBy == "ID Number")
            {
                return(View(db.Employees.Where(x => x.IDNumber.StartsWith(search) || search == null).ToList()));
            }
            else
            {
                return(View(db.Employees.Where(x => x.Name.StartsWith(search) || search == null).ToList()));
            }
        }
Пример #9
0
        public ActionResult Index(string searchBy, string search)
        {
            //int d=ConvertTo...
            v.DateAccessed   = DateTime.Now;
            v.TableAccessed  = "Client";
            v.ChangesMade    = "Viewed Clients Table";
            v.AuditLogTypeID = 1;
            //v.UserID = eqp.user.UserID;
            db.AuditLogs.Add(v);
            db.SaveChanges();

            if (searchBy == "Contact Number")
            {
                return(View(db.Clients.Where(x => x.ContactNumber == search || search == null).ToList()));
            }
            else
            {
                return(View(db.Clients.Where(x => x.ClientName.StartsWith(search) || search == null).ToList()));
            }
        }
Пример #10
0
        public ActionResult ResetPassword(User model)
        {
            try
            {
                var message = "";
                //if (ModelState.IsValid)
                //{

                SpartanFireDBEntities1 unew = new SpartanFireDBEntities1();
                //int num = model.UserID;
                //where model.password = u .password

                var cc = unew.Users.Where(a => a.UserEmail == model.UserEmail).FirstOrDefault();
                cc.UserPassword = (model.UserPassword);
                //unew.Users.Find(25).UserPassword = model.UserPassword;
                //user.UserEmail = "";
                //dc.Configuration.ValidateOnSaveEnabled = false;
                unew.SaveChanges();
                message = "New password updated successfully";


                //}
                //else
                //{
                //    message = "Something invalid";
                //}
                ViewBag.Message = message;
                return(View(model));
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
Пример #11
0
        public RedirectToRouteResult UpdatingStatus(int?id, int?sid)
        {
            SupplierOrder so;

            db.Configuration.ProxyCreationEnabled = false;
            so = db.SupplierOrders.Find(id);
            so.SupplierStatusID = (int)sid;
            if (sid == 5)
            {
                so.SupplierOrderLines = db.SupplierOrderLines.Include(sol => sol.Product).Where(sol => sol.SupplierOrderID == id).ToList();
                foreach (var item in so.SupplierOrderLines)
                {
                    item.Product.QuantityOnHand = -item.QuantityReceived;
                }
                db.SaveChanges();
            }
            HttpResponseMessage update = GlobalVariables.WebAPIClient.PutAsJsonAsync("SupplierOrder/" + id, so).Result;

            if (sid == 5)
            {
                TempData["SuccessMessage"] = "Order returned";
            }
            else if (sid == 3)
            {
                TempData["SuccessMessage"] = "Order received in full";
            }
            else if (sid == 4)
            {
                TempData["SuccessMessage"] = "Order cancelled";
            }
            else if (sid == 2)
            {
                TempData["SuccessMessage"] = "Order partially received - put on backordered";
            }
            return(RedirectToAction("Index"));
        }
Пример #12
0
        public ActionResult AddProductToCart(int?id)
        {
            if (Session["UserID"] == null)
            {
                TempData["message"] = "Please login to place an order order";
                return(RedirectToAction("Index", "Login"));
            }
            int user = Convert.ToInt32(Session["UserID"]);

            db.Configuration.ProxyCreationEnabled = false;
            mvcProductModel     pm;
            HttpResponseMessage re = GlobalVariables.WebAPIClient.GetAsync("Product/" + id.ToString()).Result;// finds the product

            pm = re.Content.ReadAsAsync <mvcProductModel>().Result;
            ProductOrder productorder = db.ProductOrders.Where(po => po.ProductOrderStatusID == 1)
                                        .Include(po => po.Location)
                                        .Include(po => po.Location.Client)
                                        .Include(po => po.ProductOrderLines.Select(line => line.Product))
                                        .Where(po => po.Location.Client.UserID == user)
                                        .FirstOrDefault();

            if (productorder == null)//if no order started
            {
                ProductOrderLine pl = new ProductOrderLine();
                productorder         = new ProductOrder();
                pl.ProductID         = pm.ProductID;
                pl.QuantityOrdered   = 1;
                pl.QuantityDelivered = 0;
                productorder.ProductOrderStatusID = 1;
                productorder.LocationID           = db.Locations.Where(l => l.Client.UserID == user)
                                                    .Select(l => l.LocationID).FirstOrDefault();
                productorder.Client_ID = db.Clients.Where(c => c.UserID == user)
                                         .Select(c => c.ClientID).FirstOrDefault();
                db.ProductOrders.Add(productorder);
                db.SaveChanges();
                List <int> orderIDs = db.ProductOrders.Where(po => po.ProductOrderStatusID == 1).Select(po => po.ProductOrderID).ToList();
                pl.ProductOrderID = orderIDs.Last();
                db.ProductOrderLines.Add(pl);
                db.SaveChanges();
            }
            else//if order started (in cart)
            {
                bool inCart = false;
                foreach (ProductOrderLine line in productorder.ProductOrderLines)
                {
                    if (line.ProductID == pm.ProductID)
                    {
                        inCart = true;
                        line.QuantityOrdered += 1;
                        db.SaveChanges();
                        break;
                    }
                }
                if (!inCart)
                {
                    ProductOrderLine tmp = new ProductOrderLine();
                    tmp.ProductID         = pm.ProductID;
                    tmp.QuantityOrdered   = 1;
                    tmp.QuantityDelivered = 0;
                    tmp.ProductOrderID    = productorder.ProductOrderID;
                    productorder.ProductOrderLines.Add(tmp);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Checkout", "ProductOrder", new { id = productorder.ProductOrderID }));
        }
Пример #13
0
        public ActionResult AddorEdit(EmployeeRequest model, int EmployeeID)
        {
            model.EmployeeID = EmployeeID;
            try
            {
                var exists = db.EmployeeRequests.Where(x => x.EmployeeID == EmployeeID & x.ServiceRequestID == model.ServiceRequestID);
                if (exists.Count() == 0)
                {
                    var DateBooked = db.ServiceRequests.ToList().FirstOrDefault(x => x.ServiceRequestID == ServiceRequestID).ServiceBookedDate;

                    var BookedAlready = (from a in db.ServiceRequests.Where(x => x.ServiceBookedDate == DateBooked)
                                         join b in db.EmployeeRequests.Where(x => x.EmployeeID == EmployeeID)
                                         on a.ServiceRequestID equals b.ServiceRequestID
                                         select new
                    {
                        a.ServiceRequestID
                    }).ToList();

                    if (BookedAlready.Count() == 0)
                    {
                        HttpResponseMessage response = GlobalVariables.WebAPIClient.PostAsJsonAsync("EmployeeRequest", model).Result;

                        TempData["SuccessMessage"] = "Saved Successfully";

                        n.DateAccessed   = DateTime.Now;
                        n.TableAccessed  = "Client";
                        n.ChangesMade    = "Created New Client";
                        n.AuditLogTypeID = 2;
                        n.UserID         = model.UserID;
                        db.AuditLogs.Add(n);
                        db.SaveChanges();

                        return(RedirectToAction("AddorEdit", "EmployeeRequest"));
                    }
                    else
                    {
                        TempData["SuccessMessage"] = "Error: Employee already booked for the day";
                    }
                }
                else
                {
                    TempData["SuccessMessage"] = "Error: Exists already";
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
            model.EmployeeRequestList = db.EmployeeRequests.Where(x => x.ServiceRequestID == model.ServiceRequestID).ToList();
            model.Employee            = new Employee();
            foreach (var item in model.EmployeeRequestList)
            {
                item.Employee = db.Employees.Where(x => x.EmployeeID == item.EmployeeID).FirstOrDefault();
            }
            model.EmployeeList = db.Employees.Where(x => x.EmployeeTypeID == 2).ToList();
            return(View(model));
        }