private static Job CreateNewJob(long userID, long workTypeId, int v)
        {
            //Creating the Mater Job Object
            Job NewJob = new Job();

            NewJob.CusID       = userID;
            NewJob.JobStatusID = 1;
            NewJob.WorkTypeID  = workTypeId;

            NewJob.ReceiveDate = DateTime.Now.Date;
            //NewJob.CompletedBy = default(string);
            //NewJob.CompletedDate = default(DateTime);
            //NewJob.CoordinatorID = default(long);
            SMPEntities entity = new SMPEntities();

            NewJob.FinanceID = entity.Finances.FirstOrDefault(x => x.WorkTypeID == workTypeId).ID;
            //NewJob.SupplierID = default(long);
            //NewJob.ProductID = default(long);
            //Creation Done.
            return(NewJob);
        }
        public ActionResult Complete()
        {
            W_install    = 0;
            W_exchange   = 0;
            W_reallocate = 0;
            W_remove     = 0;

            HttpCookie c        = Request.Cookies["Username"];
            string     username = null;

            // Retrieving UserId from the username and also fetching the user address.

            SMPEntities context = new SMPEntities();

            if (c != null)
            {
                username = c.Value;
            }
            string HtmlString = ConvertViewToString("~/Views/Customer/Email.cshtml");
            bool   m          = Email.Send(username, "Your Order Confirmation", HtmlString);

            return(View());
        }
        public ActionResult Welcome()
        {
            HttpCookie c = Request.Cookies["Admin"];

            if (c == null)
            {
                return(RedirectToAction("index"));
            }

            // For Assigning coordinator Id for job Id
            long JobId = 0, CoordId = 0, SuppId = 0;

            ViewBag.Coord    = 1;
            ViewBag.Supplier = 1;
            if (Request["AssignCoordinator"] != null)
            {
                JobId = long.Parse(Request["AssignCoordinator"]);
                using (SMPEntities contextt = new SMPEntities())
                {
                    var user = contextt.UserProfiles.FirstOrDefault(x => x.RoleId == 2 && x.Assigned == 0);


                    if (user != null)
                    {
                        CoordId       = user.ID;
                        user.Assigned = 1;
                        contextt.SaveChanges();
                    }
                    else
                    {
                        ViewBag.Coord = 0;
                    }
                }

                if (CoordId != 0)
                {
                    var job = new Job()
                    {
                        ID = JobId, JobStatusID = 2, CoordinatorID = CoordId
                    };
                    if (job != null)
                    {
                        entities.Jobs.Attach(job);
                        entities.Entry(job).Property(x => x.JobStatusID).IsModified   = true;
                        entities.Entry(job).Property(x => x.CoordinatorID).IsModified = true;

                        entities.SaveChanges();
                        entities.Entry(job).State = EntityState.Detached;
                    }
                }
            }
            if (Request["AssignSupplier"] != null)
            {
                JobId = long.Parse(Request["AssignSupplier"]);
                using (SMPEntities contextt = new SMPEntities())
                {
                    var user = contextt.UserProfiles.FirstOrDefault(x => x.RoleId == 4 && x.Assigned == 0);

                    if (user != null)
                    {
                        SuppId = user.ID;

                        user.Assigned = 1;

                        contextt.SaveChanges();
                    }
                    else
                    {
                        ViewBag.Supplier = 0;
                    }
                }

                if (SuppId != 0)
                {
                    var job = new Job()
                    {
                        ID = JobId, JobStatusID = 3, SupplierID = SuppId
                    };
                    if (job != null)
                    {
                        entities.Jobs.Attach(job);
                        entities.Entry(job).Property(x => x.JobStatusID).IsModified = true;
                        entities.Entry(job).Property(x => x.SupplierID).IsModified  = true;
                        entities.SaveChanges();
                        entities.Entry(job).State = EntityState.Detached;
                    }
                }
            }


            var list = entities.Jobs.ToList();

            List <DisplayJob> Dlist = new List <DisplayJob>();

            foreach (var x in list)
            {
                DisplayJob job = new DisplayJob();
                job.ID            = x.ID;
                job.CusID         = x.CusID;
                job.JobStatus     = entities.JobStatus.FirstOrDefault(y => y.ID == x.JobStatusID).Name;
                job.ReceiveDate   = x.ReceiveDate;
                job.SupplierID    = x.SupplierID;
                job.WorkType      = entities.WorkTypes.FirstOrDefault(y => y.ID == x.WorkTypeID).Name;
                job.CompletedBy   = x.CompletedBy;
                job.CompletedDate = x.CompletedDate;
                job.Amount        = entities.Finances.FirstOrDefault(y => y.ID == x.FinanceID).Sale;
                job.CoordinatorID = x.CoordinatorID;

                Dlist.Add(job);
            }

            return(View(Dlist));
        }
示例#4
0
        public ActionResult Welcome()
        {
            HttpCookie c = Request.Cookies["Coordinator"];

            if (c == null)
            {
                return(RedirectToAction("index"));
            }

            // For Assigning coordinator Id for job Id
            long?JobId = 0, CoordId = 0, SuppId = 0;

            if (Request["Complete"] != null)
            {
                JobId = long.Parse(Request["Complete"]);
                long custid    = 0;
                long jobtypeid = 0;
                using (SMPEntities contextt = new SMPEntities())
                {
                    var Job = contextt.Jobs.FirstOrDefault(x => x.ID == JobId);
                    {
                        custid    = Job.CusID;
                        CoordId   = Job.CoordinatorID;
                        SuppId    = Job.SupplierID;
                        jobtypeid = Job.WorkTypeID;
                        contextt.Jobs.Remove(Job);
                        contextt.SaveChanges();
                    }
                }
                if (jobtypeid == 1)
                {
                    using (SMPEntities contextt = new SMPEntities())
                    {
                        var Data = new Power_Consumption();


                        if (Data != null)
                        {
                            Data.CustID = custid;
                            Data.Usage  = 100;
                            contextt.Power_Consumption.Add(Data);

                            contextt.SaveChanges();
                        }
                    }
                }
                using (SMPEntities contextt = new SMPEntities())
                {
                    var user = contextt.UserProfiles.FirstOrDefault(x => x.ID == CoordId);
                    if (user != null)
                    {
                        user.Assigned = 0;
                        contextt.SaveChanges();
                    }
                }
                using (SMPEntities contextt = new SMPEntities())
                {
                    var user = contextt.UserProfiles.FirstOrDefault(x => x.ID == SuppId);
                    if (user != null)
                    {
                        user.Assigned = 0;
                        contextt.SaveChanges();
                    }
                }
            }


            var list = entities.Jobs.Where(x => x.CoordinatorID != null).ToList();

            List <DisplayJob> Dlist = new List <DisplayJob>();

            foreach (var x in list)
            {
                DisplayJob job = new DisplayJob();
                job.ID            = x.ID;
                job.CusID         = x.CusID;
                job.JobStatus     = entities.JobStatus.FirstOrDefault(y => y.ID == x.JobStatusID).Name;
                job.ReceiveDate   = x.ReceiveDate;
                job.SupplierID    = x.SupplierID;
                job.WorkType      = entities.WorkTypes.FirstOrDefault(y => y.ID == x.WorkTypeID).Name;
                job.CompletedBy   = x.CompletedBy;
                job.CompletedDate = x.CompletedDate;
                job.Amount        = entities.Finances.FirstOrDefault(y => y.ID == x.FinanceID).Sale;
                job.CoordinatorID = x.CoordinatorID;

                Dlist.Add(job);
            }

            return(View(Dlist));
        }