/// <summary>
        /// Updates / Inserts new Job
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public int UpsertJob(tblJob job)
        {
            if (job.JobID == 0) //new record
            {
                try
                {
                    dc.tblJobs.InsertOnSubmit(job);
                    dc.SubmitChanges();

                    return(job.JobID);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else // update
            {
                try
                {
                    var record = dc.tblJobs.FirstOrDefault(x => x.JobID == job.JobID);
                    record = job;
                    dc.SubmitChanges();

                    return(record.JobID);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #2
0
 public DaybookModel(tblJob job)
 {
     this.JobID           = job.JobID;
     this.CustomerName    = job.CustomerName;
     this.CustomerID      = job.CustomerID;
     this.dtTo            = job.dtTo;
     this.dtFrom          = job.dtFrom;
     this.DriverName      = job.DriverName;
     this.DriverTimeStamp = job.DriverTimeStamp;
     this.DriverID        = job.DriverID;
     this.MiscCode        = job.MiscCode;
     this.Type            = job.Type;
     this.JobRef          = job.JobRef;
     this.CustRef         = job.CustRef;
     this.Area            = job.Area;
     this.Journey         = job.Journey;
     this.BasePrice       = job.BasePrice;
     this.Time            = job.Time;
     this.InvoiceNo       = job.InvoiceNo;
     this.Notes           = job.Notes;
     this.Address         = job.Address;
     this.Address         = job.Address;
     this.TruckId         = job.TruckId;
     this.TrailerId       = job.TrailerId;
     this.PinNumber       = job.PinNumber;
     this.UseReturn       = Convert.ToBoolean(job.UseReturn);
     this.TimeString      = job.Time == null?DateTime.Now.TimeOfDay.ToString() : Convert.ToDateTime(job.Time).TimeOfDay.ToString();
 }
Exemple #3
0
 public JobModel AddAndUpdateJob(JobModel model)
 {
     try
     {
         if (model.ID > 0)
         {
             var record = _db.tblJobs.OrderByDescending(x => x.ID).Where(x => x.ID == model.ID).FirstOrDefault();
             record.Job       = model.Job;
             record.MinSalary = model.MinSalary;
             record.MaxSalary = model.MaxSalary;
             _db.SaveChanges();
         }
         else
         {
             tblJob _job = new tblJob();
             _job.Job       = model.Job;
             _job.MinSalary = model.MinSalary;
             _job.MaxSalary = model.MaxSalary;
             _db.tblJobs.Add(_job);
             _db.SaveChanges();
             model.ID = _job.ID;
         }
     }
     catch (Exception ex)
     {
     }
     return(model);
 }
        public ActionResult PostJob(JobViewModel jvm)
        {
            string      user = User.Identity.Name;
            tblUser     tb   = _db.tblUsers.Where(a => a.Username == user).FirstOrDefault();
            tblEmployer tbe  = _db.tblEmployers.Where(b => b.UserId == tb.UserId).FirstOrDefault();
            tblJob      tbj  = new tblJob();

            tbj.CategoryId    = jvm.CategoryId;
            tbj.EmployerId    = tbe.EmployerId;
            tbj.SalaryRange   = jvm.SalaryRange;
            tbj.JobType       = jvm.JobType;
            tbj.JobDetails    = jvm.JobDetails;
            tbj.isFeaturedJob = jvm.isFeaturedJob;
            tbj.PostedDate    = DateTime.Now;
            tbj.ExpiryDate    = jvm.ExpiryDate;
            _db.tblJobs.Add(tbj);
            _db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Exemple #5
0
        public DBResult SaveDaybook(DaybookModel job)
        {
            tblJob tblJob = job.JobID != 0 ? db.tblJobs.FirstOrDefault(j => j.JobID == job.JobID) : new tblJob();

            try
            {
                tblJob.Address      = job.Address;
                tblJob.Area         = job.Area;
                tblJob.BasePrice    = job.BasePrice;
                tblJob.CustomerID   = job.CustomerID;
                tblJob.CustRef      = job.CustRef;
                tblJob.CustomerName = job.CustomerName;
                tblJob.DriverName   = job.DriverName;
                tblJob.dtFrom       = job.dtFrom;
                tblJob.dtTo         = job.dtTo;
                tblJob.Notes        = job.Notes;
                tblJob.Time         = job.Time;
                tblJob.Journey      = job.Journey;
                tblJob.Type         = job.Type;
                tblJob.MiscCode     = job.MiscCode;
                tblJob.TruckId      = job.TruckId;
                tblJob.PinNumber    = job.PinNumber;
                tblJob.TrailerId    = job.TrailerId;
                tblJob.UseReturn    = job.UseReturn;
                tblJob.JobRef       = job.JobRef;
                tblJob.InvoiceNo    = job.InvoiceNo;

                if (job.JobID == 0)
                {
                    tblJob.DriverID = job.DriverID;
                    db.tblJobs.Add(tblJob);
                    if (job.UseReturn)
                    {
                        var dateFrom = Convert.ToDateTime(tblJob.dtFrom).AddDays(1);
                        var dateTo   = Convert.ToDateTime(tblJob.dtTo).AddDays(1);

                        var currentDateUsed = dateFrom;
                        while (currentDateUsed < dateTo)
                        {
                            tblJob retJob = new tblJob();
                            retJob.DriverID     = job.DriverID;
                            retJob.Address      = job.Address;
                            retJob.Area         = job.Area;
                            retJob.BasePrice    = job.BasePrice;
                            retJob.CustomerID   = job.CustomerID;
                            retJob.CustRef      = job.CustRef;
                            retJob.CustomerName = job.CustomerName;
                            retJob.DriverName   = job.DriverName;
                            retJob.dtFrom       = currentDateUsed;
                            retJob.dtTo         = job.dtTo;
                            retJob.Notes        = job.Notes;
                            retJob.Time         = job.Time;
                            retJob.Journey      = job.Journey;
                            retJob.Type         = job.Type;
                            retJob.MiscCode     = dateFrom == dateTo.AddDays(-2) ? string.Format("{0}-RETURNED", job.MiscCode) : job.MiscCode;
                            retJob.TruckId      = job.TruckId;
                            retJob.PinNumber    = job.PinNumber;
                            retJob.TrailerId    = job.TrailerId;
                            retJob.UseReturn    = job.UseReturn;
                            retJob.JobRef       = job.JobRef;
                            retJob.dtFrom       = currentDateUsed;
                            db.tblJobs.Add(retJob);
                            currentDateUsed = currentDateUsed.AddDays(1);
                        }
                    }
                }
                else
                {
                    if (job.IsDuplicate)
                    {
                        if (tblJob.DriverID == job.DriverID)
                        {
                            tblJob.DuplicateOf = job.JobID;
                            var duplicatesFound = db.tblJobs.Count(j => j.DuplicateOf == job.JobID);
                            tblJob.DriverName = string.Format("{0} ({1})", job.DriverName, (duplicatesFound + 2));
                        }

                        tblJob.DriverID = job.DriverID;
                        db.tblJobs.Add(tblJob);
                    }
                }

                db.SaveChanges();
                return(new DBResult {
                    ReturnCode = ReturnCode.Success
                });
            }
            catch (Exception ex)
            {
                return(new DBResult {
                    ReturnCode = ReturnCode.Failed, Message = ex.Message
                });
            }
        }