예제 #1
0
        // GET: Job/Edit
        public ActionResult Edit(int id)
        {
            var service = CreateJobService();
            var detail  = service.GetJobById(id);
            var model   =
                new JobEdit
            {
                ClientId  = detail.ClientId,
                ServiceId = detail.ServiceId,
                PetIds    = detail.PetIds,
                StartDate = DateTime.Parse(detail.StartDate),
                StartTime = DateTime.Parse(detail.StartTime),
                Note      = detail.Note,
            };

            var clients = service.GetClients();

            ViewBag.Clients        = clients;
            ViewBag.SelectedClient = clients.Where(client => client.ClientId == model.ClientId);

            var services = service.GetServices();

            ViewBag.Services        = services;
            ViewBag.SelectedService = services.Where(svc => svc.ServiceId == model.ServiceId);

            var pets = service.GetPets();

            ViewBag.PetIds = new SelectList(pets, "PetId", "Name");

            //var pets = service.GetPets();
            //ViewBag.Pets = pets;
            //ViewBag.SelectedPets = pets.Where(pets => pets.PetIds == model.PetIds);

            return(View(model));
        }
예제 #2
0
        public ActionResult Edit(int id, JobEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.JobId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateJobService();

            if (service.UpdateJob(model))
            {
                TempData["SaveResult"] = $"{model.CompanyName}'s Job Was Updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", $"{model.CompanyName}'s Job Could Not Be Updated.");

            var skillList = new SelectList(service.SkillList(), "SkillId", "SkillName", model.SkillId);

            ViewBag.SkillId = skillList;
            var locationList = new SelectList(service.LocationList(), "LocationId", "FullLocation", model.LocationId);

            ViewBag.LocationId = locationList;

            return(View(model));
        }
예제 #3
0
        public ActionResult Edit(int id, JobEdit model)
        {
            if (ModelState.IsValid)
            {
                var service = CreateJobService();
                service.UpdateJob(model);
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
예제 #4
0
 /// <summary>コンストラクタ(編集、コピー新規用)</summary>
 /// <param name="innerJobnetId">実行ジョブネットID</param>
 public SubJobEdit(JobArrangerWindow parentWindow, string jobnetId, string updDate, Consts.EditType editType, bool needFocus)
 {
     InitializeComponent();
     jobEdit     = new JobEdit(parentWindow, jobnetId, updDate, editType);
     _successFlg = false;
     if (jobEdit.SuccessFlg)
     {
         _successFlg = true;
     }
     jobEdit.IsSubJobnet = true;
     SubJobnetGrid.Children.Add(jobEdit);
     _needFocus = needFocus;
 }
        public ActionResult Edit(int id)
        {
            var service = CreateJobService();
            var detail  = service.GetJobById(id);
            var model   =
                new JobEdit
            {
                JobId              = detail.JobId,
                TitleOfJob         = detail.TitleOfJob,
                Description        = detail.Description,
                Pay                = detail.Pay,
                EquipmentAvailable = detail.EquipmentAvailable
            };

            return(View(model));
        }
예제 #6
0
        public JobEdit CreateJob()
        {
            var cRepo = new ClientRepository();

            var sRepo = new JobStatuRepository();

            var job = new JobEdit()
            {
                //Id = ToString(),
                Id = Guid.NewGuid().ToString(),
                // Id = string.IsNullOrEmpty(string).ToString(),
                Client = cRepo.GetClients(),
                //JobStatu = sRepo.GetJobStatus()
            };

            return(job);
        }
예제 #7
0
        public JobEdit CreateJob()
        {
            var cRepo = new ClientRepository();



            var job = new JobEdit()
            {
                //Id = ToString(),
                JobId = Guid.NewGuid().ToString(),

                Clients = cRepo.GetClients(),
                //JobStatu = sRepo.GetJobStatus()
            };

            return(job);
        }
예제 #8
0
        public bool UpdateJob(JobEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Jobs
                    .Single(e => e.CurrentJobId == model.CurrentJobId);

                entity.Address      = model.Address;
                entity.CurrentJobId = model.CurrentJobId;
                entity.Title        = model.Title;
                entity.Owner        = model.Owner;


                return(ctx.SaveChanges() == 1);
            }
        }
예제 #9
0
 public ActionResult EditJobPartial(JobEdit model)
 {
     if (ModelState.IsValid)
     {
         var  repo  = new JobRepository();
         bool saved = repo.SaveJob(model);
         if (saved)
         {
             bool isGuid = Guid.TryParse(model.JobId, out Guid jobId);
             if (isGuid)
             {
                 var modelUpdate = repo.GetJob(jobId);
                 return(PartialView(modelUpdate));
             }
         }
     }
     return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
 }
예제 #10
0
        public bool UpdateJob(JobEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Jobs
                    .Single(e => e.JobId == model.JobId && e.OwnerId == _userId);

                entity.TitleOfJob         = model.TitleOfJob;
                entity.Description        = model.Description;
                entity.Pay                = model.Pay;
                entity.EquipmentAvailable = model.EquipmentAvailable;
                entity.ModifiedUtc        = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #11
0
        //this include here is to add Linq to find a job with jobId that matches the data about other objects
        //in the data's being returned the the db
        public JobEdit GetJob(Guid id)
        {
            if (id != Guid.Empty)
            {
                using (var context = new CloudbassContext())
                {
                    var job = context.Jobs.AsNoTracking()
                              .Where(j => j.JobId == id)
                              //.Include(j => j.Crews)
                              //.FirstOrDefault();
                              .Single();

                    if (job != null)
                    {
                        var jobEditVm = new JobEdit()
                        {
                            JobId       = job.JobId.ToString("D"),
                            text        = job.text.Trim(),
                            Description = job.Description,
                            //NameConcatenateLocation = j.
                            DateCreated = job.DateCreated,
                            Location    = job.Location,
                            Coordinator = job.Coordinator,
                            // ClientName = j.Client.Name,

                            start_date       = job.start_date,
                            TXDate           = job.TXDate,
                            end_date         = job.end_date,
                            CommercialLead   = job.CommercialLead,
                            SelectedClientId = job.Client.Id,
                            //JobRef = job.JobRef,
                            Status = job.Status
                        };
                        var clientsRepo = new ClientRepository();
                        jobEditVm.Clients = clientsRepo.GetClients();
                        //var jobStatuRepo = new JobStatuRepository();
                        //jobEditVm.JobStatu = jobStatuRepo.GetJobStatus();

                        return(jobEditVm);
                    }
                }
            }
            return(null);
        }
예제 #12
0
        public bool UpdateJob(JobEdit model)
        {
            var jobEntity = _context.Jobs.Find(model.JobId);

            jobEntity.ClientId  = model.ClientId;
            jobEntity.ServiceId = model.ServiceId;
            jobEntity.StartDate = model.StartDate;
            jobEntity.StartTime = model.StartTime;
            jobEntity.Note      = model.Note;

            int savedChangeToJobs = _context.SaveChanges();

            var petAssignments = _context.PetsToJobs.Where(e => e.JobId == model.JobId);

            // Pets on job - Is model equal to persistence?
            List <int> petIds   = petAssignments.Select(e => e.PetId).ToList();
            bool       areEqual = Enumerable.SequenceEqual(petIds.OrderBy(e => e), model.PetIds.OrderBy(e => e));

            // If not, delete all and reassign
            if (!areEqual)
            {
                foreach (var petAssignment in petAssignments)
                {
                    _context.PetsToJobs.Remove(petAssignment);
                }

                int savedChangesToPetAssignments = 0;
                foreach (var petId in model.PetIds)
                {
                    var assignmentEntity = new PetToJob
                    {
                        PetId = petId,
                        JobId = jobEntity.JobId
                    };
                    _context.PetsToJobs.Add(assignmentEntity);
                    savedChangesToPetAssignments += _context.SaveChanges();
                }

                return(savedChangeToJobs + savedChangesToPetAssignments == 1 + model.PetIds.Count());
            }

            return(savedChangeToJobs == 1);
        }
예제 #13
0
        public IHttpActionResult UpdateJob(JobEdit model, int jobid)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (model?.JobId != jobid)
            {
                return(BadRequest("Job id do not match with the model Id"));
            }
            JobServices jobservices = CreateJobServices();
            var         jobs        = jobservices.UpdateJob(model, jobid);

            if (jobs is false)
            {
                return(InternalServerError());
            }
            return(Ok("job updated successfully"));
        }
예제 #14
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);
        }
예제 #15
0
 public ActionResult Create([Bind(Include = "JobId, text,Description, SelectedClientId, DateCreated, Location, Coordinator,start_date, TXDate, end_date, CommercialLead, ")] JobEdit model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var  repo  = new JobRepository();
             bool saved = repo.SaveJob(model);
             if (saved)
             {
                 return(RedirectToAction("Index"));
             }
         }
         return(View());
     }
     catch
     {
         return(View());
     }
 }
예제 #16
0
        public JobEdit GetJob(string id)
        {
            if (id != string.Empty)
            {
                using (var context = new CBDBEntities())
                {
                    var job = context.Jobs.AsNoTracking()
                              .Where(j => j.Id == id)
                              .Single();

                    if (job != null)
                    {
                        var jobEditVm = new JobEdit()
                        {
                            Id          = job.Id /*.ToString("")*/,
                            text        = job.text.Trim(),
                            Description = job.Description,
                            //NameConcatenateLocation = j.
                            DateCreated = job.DateCreated,
                            Location    = job.Location,
                            Coordinator = job.Coordinator,
                            // ClientName = j.Client.Name,

                            start_date     = job.start_date,
                            TXDate         = job.TXDate,
                            end_date       = job.end_date,
                            CommercialLead = job.CommercialLead,
                            SelectedClient = job.Client.Id,
                            //SelectedStatus = job.JobStatu.Id
                        };
                        var clientsRepo = new ClientRepository();
                        jobEditVm.Client = clientsRepo.GetClients();
                        //var jobStatuRepo = new JobStatuRepository();
                        //jobEditVm.JobStatu = jobStatuRepo.GetJobStatus();

                        return(jobEditVm);
                    }
                }
            }
            return(null);
        }
예제 #17
0
        public bool SaveJob(JobEdit jobedit)
        {
            if (jobedit != null)
            {
                using (var context = new CBDBEntities())
                {
                    // if (string.IsNullOrEmpty(jobedit.Id))
                    if (Guid.TryParse(jobedit.Id, out Guid newGuid))
                    {
                        var job = new Models.Job()
                        {
                            Id = newGuid.ToString(),
                            // Id = ToString(),
                            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.SelectedClient,
                            // statusId = jobedit.SelectedStatus,
                            CommercialLead = jobedit.CommercialLead
                        };

                        job.Client = context.Clients.Find(jobedit.SelectedClient);
                        //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);
        }
예제 #18
0
        public bool UpdateJob(JobEdit model, int id)


        {
            using (var ctx = new ApplicationDbContext())
            {
                var job = ctx
                          .Jobs
                          .SingleOrDefault(j => j.OwnerId == _UserId && j.JobId == id);
                if (job is null)
                {
                    return(false);
                }
                job.JobPosition    = model.JobPosition;
                job.JobRequirement = model.JobRequirement;
                job.JobType        = model.JobType;
                job.Salary         = model.Salary;
                job.JobDescription = model.JobDescription;

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #19
0
        public bool UpdateJob(JobEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Jobs
                    .Single(e => e.JobId == model.JobId && e.OwnerId == _userId);

                entity.CompanyName    = model.CompanyName;
                entity.JobDescription = model.JobDescription;


                entity.LocationId = model.LocationId;
                entity.SkillId    = model.SkillId;


                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #20
0
        public ActionResult Edit(int id)
        {
            var service   = CreateJobService();
            var skillList = new SelectList(service.SkillList(), "SkillId", "SkillName");

            ViewBag.SkillId = skillList;
            var locationList = new SelectList(service.LocationList(), "LocationId", "FullLocation");

            ViewBag.LocationId = locationList;

            var detail = service.GetJobById(id);
            var model  =
                new JobEdit
            {
                CompanyName    = detail.CompanyName,
                JobId          = detail.JobId,
                SkillId        = detail.SkillId,
                JobDescription = detail.JobDescription,
                LocationId     = detail.LocationId
            };

            return(View(model));
        }
        public ActionResult Edit(int id, JobEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.JobId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateJobService();

            if (service.UpdateJob(model))
            {
                TempData["SaveResult"] = "Your job was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your note could not be updated.");
            return(View(model));
        }