Пример #1
0
 public ActionResult AssignJob(job_assignment job_assignment, string id)
 {
     try
     {
         string[] userIds = id.Split(',');
         for (int i = 0; i < userIds.Length; i++)
         {
             if (userIds[i] != "")
             {
                 int userId = Convert.ToInt32(userIds[i]);
                 job_assignment.user_id = userId;
                 var jobAssign = db.job_assignment.AsEnumerable().Where(x => x.job_id == job_assignment.job_id && x.user_id == userId && x.is_active).FirstOrDefault();
                 if (jobAssign != null)
                 {
                     db.job_assignment.Remove(jobAssign);
                     db.SaveChanges();
                     result.Message = string.Format(BaseConst.MSG_SUCCESS_DELETE, "Job Assign");
                 }
                 db.job_assignment.Add(job_assignment);
                 db.SaveChanges();
                 result.MessageType = MessageType.Success;
                 result.Message     = string.Format(BaseConst.MSG_SUCCESS_CREATE, "Job Assign");
             }
         }
     }
     catch (Exception ex)
     {
         result.MessageType = MessageType.Error;
         result.Message     = ex.Message;
     }
     return(RedirectToAction("Index", new { Result = result.Message, MessageType = result.MessageType }));
 }
Пример #2
0
 public ActionResult CreteEditJob(job job, FormCollection frm)
 {
     try
     {
         string jobComment = "";
         if (job.job_id > 0)
         {
             jobComment = db.jobs.Find(job.job_id).comment;
         }
         var jobCode = "";///db.jobs.AsEnumerable().Where(x => x.company_id == SessionUtil.GetCompanyID()).Max(x => x.job_id).ToString();
         result = jobUtil.PostCreteEditJob(job, jobComment, jobCode);
         if ((Int32)result.Id > 0)
         {
             var user_id = string.IsNullOrEmpty(frm["user_id"])?0:Convert.ToInt32(frm["user_id"]);
             if (user_id > 0)
             {
                 var jobAssign = db.job_assignment.AsEnumerable().Where(x => x.job_id == (Int32)result.Id && x.user_id == user_id && x.is_active).FirstOrDefault();
                 if (jobAssign != null)
                 {
                     db.job_assignment.Remove(jobAssign);
                     db.SaveChanges();
                     result.Message = string.Format(BaseConst.MSG_SUCCESS_DELETE, "Job Assign");
                 }
                 job_assignment job_assignment = new job_assignment();
                 job_assignment.job_id  = (Int32)result.Id;
                 job_assignment.user_id = user_id;
                 db.job_assignment.Add(job_assignment);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         result.Message = ex.Message;
     }
     return(RedirectToAction("CreateEditJob", "Job", new { id = result.Id, Result = result.Message, MessageType = result.MessageType }));
 }