예제 #1
0
        public ActionResult GetEmployeeProfile(string empno, string mode = "")
        {
            try
            {
                IdmManager idm        = new IdmManager();
                var        empProfile = idm.GetEmployeeProfile(empno);
                if (empProfile == null)
                {
                    returnobj.SetError("ไม่พบข้อมูลพนักงาน");
                }
                else
                {
                    if (mode.ToLower() == "original")
                    {
                        returnobj.SetSuccess(empProfile);
                    }
                    else
                    {
                        returnobj.SetSuccess(new EmployeeViewModel(empProfile));
                    }
                }
            }
            catch (Exception ex)
            {
                returnobj.SetError(ex.Message);
            }

            return(Content(returnobj.ToJson(), "application/json"));
        }
예제 #2
0
        public ActionResult Get()
        {
            try
            {
                var currentUser  = AuthManager.GetCurrentUser();
                var employeeid   = currentUser.UserName;
                var costcenterid = currentUser.Employee.CostCenterID;

                using (var db = new BudgetContext())
                {
                    List <CostCenter> costcenterlist = new List <CostCenter>();
                    costcenterlist.Add(db.CostCenters.Where(c => c.CostCenterID == costcenterid).FirstOrDefault());

                    // Working CostCenter Condition
                    var workingCondition = db.WorkingCCs.Where(e => e.EmployeeNo == employeeid || e.CostCenterCode == costcenterid).ToList();


                    foreach (var item in workingCondition)
                    {
                        switch (item.Condition)
                        {
                        case ConditionType.ExactMatch:
                            costcenterlist.AddRange(db.CostCenters.Where(c => c.CostCenterID == item.CCAStart).ToList());
                            break;

                        case ConditionType.Between:
                            costcenterlist.AddRange(db.CostCenters.Where(c => c.CostCenterID.CompareTo(item.CCAStart) >= 0 && c.CostCenterID.CompareTo(item.CCAEnd) <= 0).ToList());
                            break;

                        case ConditionType.Contain:
                            costcenterlist.AddRange(db.CostCenters.Where(c => c.CostCenterID.StartsWith(item.CCAStart)).ToList());
                            break;

                        default:
                            break;
                        }
                    }
                    var finallist = costcenterlist.Select(c => new { c.CostCenterID, c.CostCenterName }).Distinct().OrderBy(c => c.CostCenterID).ToList();

                    returnobj.SetSuccess(finallist);
                }
            }
            catch (Exception ex)
            {
                returnobj.SetError(ex.Message);
            }

            return(Content(returnobj.ToJson(), "application/json"));
        }
예제 #3
0
        public static string ParseToJson(object obj)
        {
            //TODO Add try catch here
            try
            {
                var jsonresult = JsonConvert.SerializeObject(
                    obj,
                    Formatting.None,
                    new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                }
                    );

                return(jsonresult);
            }
            catch (Exception ex) {
                ReturnObject returnobj = new ReturnObject();
                returnobj.SetError(ex.Message);

                var jsonresult = JsonConvert.SerializeObject(
                    returnobj,
                    Formatting.None,
                    new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                }
                    );
                return(jsonresult);
            }
        }
예제 #4
0
        public ActionResult Budget(string costcenterid = "")
        {
            try
            {
                BudgetManager bm      = new BudgetManager();
                CostCenter    working = AuthManager.GetWorkingCostCenter();

                //TODO check authorize
                var budgets = bm.GetByCostCenterID(costcenterid).ToList();
                var vms     = bm.ConvertToVMs(budgets);
                returnobj.SetSuccess(vms);
            }
            catch (Exception ex)
            {
                returnobj.SetError("พบข้อผิดพลาด");
            }

            return(Content(returnobj.ToJson(), "application/json"));
        }
예제 #5
0
        public ActionResult Login(LoginViewModel logindata)
        {
            try
            {
                AuthManager.Login(logindata);
                returnobj.SetSuccess(AuthManager.GetAuthentication());
            }
            catch (Exception ex)
            {
                returnobj.SetError(ex.Message);
            }

            return(Content(returnobj.ToJson(), "application/json"));
        }
예제 #6
0
        private ActionResult Payments(string year, string costcenterid)
        {
            try
            {
                CostCenter working;
                List <PaymentViewModel> payments;
                PaymentManager          pManager = new PaymentManager();

                // 1. Get working costcenter.
                working = AuthManager.GetWorkingCostCenter();

                // 2. Get Payment data
                payments = pManager.GetOverall(year, costcenterid).ToList();

                // 3. Set Return result
                returnobj.SetSuccess(payments);
            }
            catch (Exception ex)
            {
                returnobj.SetError(ex.Message);
            }

            // 3. Return to client
            return(Content(Utility.ParseToJson(returnobj), "application/json"));
        }