public TeamOperation Get(int id) { TeamOperation teamOperation = db.TeamOperation .Where(x => x.TeamId == id) .Include(x => x.Manager) .Include(x => x.TeamOperationDetail) .ThenInclude(x => x.Account) .FirstOrDefault() ?? new TeamOperation(); teamOperation.TeamOperationDetail = (from team in db.TeamOperationDetail.Where(o => o.TeamId == teamOperation.TeamId) select new TeamOperationDetail { Id = team.Id, TeamId = team.TeamId, AccountId = team.AccountId, TeamRemark = team.TeamRemark, CreatedBy = team.CreatedBy, CreatedDate = team.CreatedDate, UpdatedBy = team.UpdatedBy, UpdatedDate = team.UpdatedDate, Approve = team.Approve, Account = db.SysAccount.Where(o => o.AccountId == team.AccountId).FirstOrDefault() }).ToList(); return(teamOperation); }
public ActionResult Delete() { Dictionary <string, dynamic> rs = new Dictionary <string, dynamic>() { { "msg", "การทำงานไม่ถูกต้อง" }, { "msgType", AlertMsgType.Danger } }; try { int id = Request.Form["TeamId"].ParseInt(); TeamOperation ob = uow.Modules.TeamOperation.Get(id); if (ob == null) { rs["msg"] = "ไม่พบข้อมูลที่ต้องการ"; rs["msgType"] = AlertMsgType.Warning; return(UrlRedirect(PathHelper.OperationTeam, rs)); } uow.Modules.TeamOperation.Delete(ob); uow.SaveChanges(); rs["msg"] = "ลบข้อมูลเรียบร้อยแล้ว"; rs["msgType"] = AlertMsgType.Success; return(UrlRedirect(PathHelper.OperationTeam, rs)); } catch (Exception ex) { rs["msg"] = ex.GetMessage(); rs["msgType"] = AlertMsgType.Danger; return(UrlRedirect(PathHelper.OperationTeam, rs)); } }
public void Delete(TeamOperation ob) { if (IsExist(ob.TeamId)) { db.TeamOperation.Remove(ob); } }
public static bool IsValid(this TeamOperation ob, out string errorMsg) { errorMsg = string.Empty; if (ob == null) { errorMsg = "ไม่พบข้อมูล"; return(false); } else { List <string> err = new List <string>(); if (string.IsNullOrWhiteSpace(ob.TeamName)) { err.Add("กรุณาระบุชื่อทีม"); } if (ob.ManagerId <= 0) { err.Add("กรุณากำหนดหัวหน้าทีม"); } if (err.Count() > 0) { errorMsg = "กรุณาตรวจสอบข้อมูลต่อไปนี้"; foreach (string s in err) { errorMsg += @"{\n}- " + s; } return(false); } return(true); } }
public ActionResult SetDetail() { Dictionary <string, dynamic> rs = new Dictionary <string, dynamic>() { { "msg", "การทำงานไม่ถูกต้อง" }, { "msgType", AlertMsgType.Danger } }; int teamId = Request.Form["teamId"].ParseInt(); string teamSaleIds = Request.Form["hdApprove"]; TeamOperation ob = uow.Modules.TeamOperation.GetSingle(teamId); bool isInsert = ob.TeamId <= 0; if (ob.TeamId <= 0) { ob.CreatedBy = CurrentUID; ob.CreatedDate = CurrentDate; } ob.TeamName = Request.Form["teamName"]; ob.ManagerId = Request.Form["managerId"].ParseInt(); ob.UpdatedBy = CurrentUID; ob.UpdatedDate = CurrentDate; try { if (!ob.IsValid(out string errMsg)) { throw new Exception(errMsg); } uow.Modules.TeamOperation.Set(ob); uow.SaveChanges(); List <TeamOperationDetail> obTeamDetail = uow.Modules.TeamOperationDetail.Gets(teamId); if (obTeamDetail != null && obTeamDetail.Count > 0 && teamSaleIds != "") { foreach (string accountId in teamSaleIds.Split(',')) { TeamOperationDetail detail = obTeamDetail.Find(o => o.AccountId == accountId.ParseLong()); detail.Approve = "1"; uow.Modules.TeamOperationDetail.Set(detail); } uow.SaveChanges(); } rs["msg"] = "บันทึกข้อมูลเรียบร้อยแล้ว"; rs["msgType"] = AlertMsgType.Success; if (isInsert) { rs.Add("id", ob.TeamId); } return(isInsert ? UrlRedirect(PathHelper.OperationTeamDetail, rs) : UrlRedirect(PathHelper.OperationTeam, rs)); } catch (Exception ex) { string msg = ex.GetMessage(); return(ViewDetail(ob, msg, AlertMsgType.Danger)); } }
public void Set(TeamOperation ob) { if (ob.TeamId == 0) { db.TeamOperation.Add(ob); } else { db.TeamOperation.Update(ob); } }
public TeamOperation GetSingle(int id) { TeamOperation teamOperation = db.TeamOperation .Where(x => x.TeamId == id) .Include(x => x.Manager) .Include(x => x.TeamOperationDetail) .ThenInclude(x => x.Account) .FirstOrDefault() ?? new TeamOperation(); return(teamOperation); }
private ActionResult ViewDetail(TeamOperation ob, string msg, AlertMsgType?msgType) { try { if (ob == null) { throw new Exception("ไม่พบข้อมูลที่ต้องการ, กรุณาลองใหม่อีกครั้ง"); } if (!string.IsNullOrWhiteSpace(msg)) { WidgetAlertModel alert = new WidgetAlertModel() { Message = msg }; if (msgType.HasValue) { alert.Type = msgType.Value; } ViewBag.Alert = alert; } ViewData["optOperation"] = uow.Modules.TeamOperation.GetNotMembers(); AccountPermission permission = new AccountPermission(); permission = GetPermissionOperation(CurrentUser.AccountId, null); ViewData["userAccount"] = CurrentUser; ViewData["optPermission"] = permission; return(View("Detail", ob)); } catch (Exception ex) { Dictionary <string, dynamic> rs = new Dictionary <string, dynamic>() { { "msg", ex.GetMessage() }, { "msgType", AlertMsgType.Danger } }; return(UrlRedirect(PathHelper.OperationTeam, rs)); } }
public ActionResult Detail(int?id, string msg, AlertMsgType?msgType) { TeamOperation ob = uow.Modules.TeamOperation.Get(id ?? 0); return(ViewDetail(ob, msg, msgType)); }
public AccountPermission GetPermissionOperation(long accountId, TeamOperation jobTeam) { AccountPermission ap = new AccountPermission(); if (accountId == 1) //admin { ap.IsManager = true; ap.IsTeam = true; ap.IsEdit = true; ap.IsAdminTeam = true; return(ap); } List <TeamOperation> manager = uow.Modules.TeamOperation.Manager(accountId); //check manager Team checkteam = uow.Modules.TeamOperation.CheckTeamOperation(accountId); //check team for non-manager //// Team Operation Admin if (checkteam != null) { if (checkteam.TeamId == 1) ///teamId 1 only { if (manager != null) { ap.IsManager = true; } else { ap.IsManager = false; } ap.IsTeam = false; ap.IsEdit = true; ap.IsAdminTeam = true; return(ap); } } //no jobTeam if (jobTeam == null) //This job are not assignment to team { if (manager != null) { ap.IsManager = true; } else { ap.IsManager = false; } ap.IsTeam = false; ap.IsEdit = false; ap.IsAdminTeam = false; return(ap); } else //this job assignment team { if (manager != null) { ap.IsManager = true; if (checkteam != null) { if (checkteam.TeamId == jobTeam.TeamId) //team curenent userid = job Team { ap.IsTeam = true; ap.IsEdit = true; //owner manager can edit ap.IsAdminTeam = false; } else //team curenent userid != job Team { ap.IsTeam = false; ap.IsEdit = false; //manager but team not match jobteam ap.IsAdminTeam = false; } } else { foreach (TeamOperation m in manager) { if (m.ManagerId == jobTeam.ManagerId) { ap.IsTeam = true; ap.IsEdit = true; //owner manager can edit ap.IsAdminTeam = false; return(ap); } } ap.IsTeam = false; ap.IsEdit = false; //other manager can't edit ap.IsAdminTeam = false; } } else { ap.IsManager = false; if (checkteam.TeamId == jobTeam.TeamId) //team curenent userid = job Team { ap.IsTeam = true; ap.IsEdit = false; //owner team ap.IsAdminTeam = false; } else //team curenent userid != job Team { ap.IsTeam = false; ap.IsEdit = false; //manager but team not match jobteam ap.IsAdminTeam = false; } } } return(ap); }