Example #1
0
        public bool SaveJob(JobEdit jobedit)
        {
            if (jobedit != null)
            {
                using (var context = new CloudbassContext())
                {
                    if (Guid.TryParse(jobedit.JobId, out Guid newGuid))
                    {
                        var job = new Models.Jobs()
                        {
                            JobId = newGuid,

                            text        = jobedit.text,
                            Description = jobedit.Description,

                            Location    = jobedit.Location,
                            Coordinator = jobedit.Coordinator,
                            DateCreated = jobedit.DateCreated,

                            //NameConcatenateLocation = jobEdit.Name,
                            start_date = jobedit.start_date,
                            TXDate     = jobedit.TXDate,
                            end_date   = jobedit.end_date,
                            ClientId   = jobedit.SelectedClientId,
                            // statusId = jobedit.SelectedStatus,
                            CommercialLead = jobedit.CommercialLead,
                            // JobRef = jobedit.JobRef,
                            Status = jobedit.Status
                        };

                        job.Client = context.Clients.Find(jobedit.SelectedClientId);
                        //job.JobStatu = context.JobStatus.Find(jobedit.SelectedStatus);
                        context.Jobs.Add(job);
                        context.SaveChanges();
                        return(true);
                    }
                }
            }

            // Return false if customeredit == null or CustomerID is not a guid
            return(false);
        }
Example #2
0
        public Jobs SaveNewJob(JobRequestModel data)
        {
            var lastJob       = context.Jobs.Where(a => a.JobName.Contains(data.Prefix) && DbFunctions.TruncateTime(a.CreatedDate) == DbFunctions.TruncateTime(DateTime.Now))?.OrderByDescending(a => a.CreatedDate).FirstOrDefault();
            int lastRunningNo = 1;

            if (lastJob != null)
            {
                lastRunningNo = Convert.ToInt32(lastJob.JobName.Substring(lastJob.JobName.Length - 3));
                lastRunningNo++;
            }
            var job = new Models.Jobs
            {
                CreatedById   = data.RequesterUserId,
                CreatedDate   = DateTime.Now,
                WarehouseType = data.Prefix == "WHD" ? 1 : 2,
                Id            = 0,
                JobName       = data.Prefix + "-" + DateTime.Now.ToString("yyyyMMdd") + "-" + lastRunningNo.ToString().PadLeft(2, '0')
            };

            context.Jobs.Add(job);
            context.SaveChanges();
            return(job);
        }