コード例 #1
0
        public ActionResult UpdateRequest(List <RequestInforModel> listRequests)
        {
            try
            {
                bool resultVisitor = true;
                // update request information
                tbl_Taxi_Request_Infor request = new tbl_Taxi_Request_Infor();
                request.Id           = listRequests[0].Id;
                request.Purpose      = listRequests[0].Purpose;
                request.ScheduleTime = listRequests[0].ScheduleTime;
                request.Pickup       = listRequests[0].Pickup;
                request.DropOff1     = listRequests[0].DropOff1;
                request.DropOff2     = listRequests[0].DropOff2;
                request.Remark       = listRequests[0].Remark;
                var resultRequest = new Taxi_RequestDao().InsertOrUpdateRequest(request);
                // update visitor information
                foreach (var item in listRequests)
                {
                    tbl_Taxi_User_Infor vis = new tbl_Taxi_User_Infor();
                    vis.Taxi_Request_Infor_Id = listRequests[0].Id;
                    vis.Name       = item.Name;
                    vis.EmployeeId = item.User_EmployeeId;
                    vis.SLM_Name   = item.SLM_Name;
                    vis.Remark     = item.User_Remark;
                    vis.UpdateBy   = mEmployee.employee.employee_id;
                    //if (request.DropOff2 != "" && request.DropOff2 != null)
                    //{

                    //}
                    resultVisitor = new Taxi_UserDao().UpdateBaseInformation(vis, item.EmployeeId_Old, request.DropOff2);
                }
                if (resultRequest && resultVisitor)
                {
                    Notification("Success", "Update visitor successfully", MyConstants.NOTIFY_SUCCESS);
                }
                else
                {
                    Notification("False", "Update visitor failure, Please recheck information!", MyConstants.NOTIFY_ERROR);
                }
            }
            catch (Exception ex)
            {
                Notification("False", "Update visitor failure, error: " + ex.ToString(), MyConstants.NOTIFY_ERROR);
            }
            return(RedirectToAction("MyRequest", "Request"));
        }
コード例 #2
0
        public ActionResult RequestDetail(List <tbl_Taxi_User_Infor> visitor)
        {
            // Update here
            try
            {
                foreach (var item in visitor)
                {
                    tbl_Taxi_User_Infor vis = new tbl_Taxi_User_Infor();
                    vis.Taxi_Request_Infor_Id = item.Taxi_Request_Infor_Id;
                    vis.Name       = item.Name;
                    vis.EmployeeId = item.EmployeeId;
                    vis.Process    = item.Process;
                    vis.Remark     = item.Remark;
                    vis.SwipeTime  = (item.SwipeTime.GetValueOrDefault().Hour == 0) ? null : item.SwipeTime;
                    vis.CardNumber = item.CardNumber;

                    if (item.CarNumber == null && item.Cost == null)
                    {
                        if (item.CardNumber != null && item.CreateBy == null)
                        {
                            vis.CreateDate = DateTime.Now;
                            vis.CreateBy   = mEmployee.employee.employee_id;
                        }
                    }
                    else
                    {
                        vis.CarNumber  = item.CarNumber;
                        vis.Cost       = item.Cost;
                        vis.RefNumber  = item.RefNumber;
                        vis.UpdateDate = DateTime.Now;
                        vis.UpdateBy   = mEmployee.employee.employee_id;
                    }
                    var result = new Taxi_UserDao().InsertOrUpdateUser(vis);
                }
                Notification("Success", "Update visitor successfully", MyConstants.NOTIFY_SUCCESS);
            }
            catch (Exception ex)
            {
                Notification("False", "Update visitor failure, error: " + ex.ToString(), MyConstants.NOTIFY_ERROR);
            }
            return(RedirectToAction("Index", "Home"));
        }
コード例 #3
0
 public bool InsertOrUpdateUser(tbl_Taxi_User_Infor user)
 {
     try
     {
         var userCheck = db.tbl_Taxi_User_Infor.FirstOrDefault(x => x.Taxi_Request_Infor_Id == user.Taxi_Request_Infor_Id &&
                                                               x.EmployeeId == user.EmployeeId && x.Process == user.Process
                                                               );
         if (userCheck == null)
         {
             db.tbl_Taxi_User_Infor.Add(user);
         }
         else
         {
             // Update item
             if (user.Cost == null && user.CarNumber == null)
             {
                 if (user.CardNumber != null && userCheck.CreateBy == null)
                 {
                     userCheck.CreateDate = user.CreateDate;
                     userCheck.CreateBy   = user.CreateBy;
                 }
             }
             userCheck.CarNumber  = user.CarNumber;
             userCheck.SwipeTime  = user.SwipeTime;
             userCheck.CardNumber = user.CardNumber;
             userCheck.Cost       = user.Cost;
             userCheck.RefNumber  = user.RefNumber;
             userCheck.UpdateDate = user.UpdateDate;
             userCheck.UpdateBy   = user.UpdateBy;
         }
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         WriteLogError.Write("InsertOrUpdateUser", ex.ToString());
         return(false);
     }
 }
コード例 #4
0
        public bool UpdateBaseInformation(tbl_Taxi_User_Infor visitor, string employeeIdOld, string dropOff2)
        {
            try
            {
                var visitorUpdate = db.tbl_Taxi_User_Infor.Where(x => x.Taxi_Request_Infor_Id == visitor.Taxi_Request_Infor_Id && x.EmployeeId == employeeIdOld);
                if (visitorUpdate == null)
                {
                    return(false);
                }
                else
                {
                    foreach (var item in visitorUpdate)
                    {
                        item.Name       = visitor.Name;
                        item.SLM_Name   = visitor.SLM_Name;
                        item.EmployeeId = visitor.EmployeeId;
                        item.Remark     = visitor.Remark;

                        // Check when dropOff2 != null
                        if (item.Process == 0 && (dropOff2 != "" && dropOff2 != null))
                        {
                            item.Process = 1;
                            // add new users
                            visitor.Process = 2;
                            db.tbl_Taxi_User_Infor.Add(visitor);
                        }
                    }
                }
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                WriteLogError.Write("UpdateBaseInformation", ex.ToString());
                return(false);
            }
        }
コード例 #5
0
        // GET: Visitor
        public JsonResult AddNewVisitor(Guid requestId, string name, string id, string company, string remark)
        {
            var newVisitor = new tbl_Taxi_User_Infor();

            newVisitor.Taxi_Request_Infor_Id = requestId;
            newVisitor.Process    = 0;
            newVisitor.Name       = name;
            newVisitor.EmployeeId = id;
            newVisitor.SLM_Name   = company;
            newVisitor.Remark     = remark;
            newVisitor.UpdateBy   = mEmployee.employee.employee_id;
            newVisitor.UpdateDate = DateTime.Now;

            var insertResult = new Taxi_UserDao().InsertOrUpdateUser(newVisitor);

            if (insertResult)
            {
                return(Json(new { result = true }));
            }
            else
            {
                return(Json(new { result = false }));
            }
        }
コード例 #6
0
        public ActionResult CreateRequest(CreateRequestModel request)
        {
            try
            {
                // Insert request infor
                tbl_Taxi_Request_Infor taxiInfor = new tbl_Taxi_Request_Infor();
                taxiInfor.Id           = request.Id;
                taxiInfor.EmployeeId   = request.EmployeeId;
                taxiInfor.Purpose      = request.Purpose;
                taxiInfor.ScheduleTime = request.ScheduleTime;
                taxiInfor.Head         = adWebHelper.GetHeadOfFunction(mEmployee.employee.access_token, mEmployee.employee.departmentName).ad_user_displayName;
                taxiInfor.Pickup       = request.Pickup;
                taxiInfor.DropOff1     = request.DropOff1;
                taxiInfor.DropOff2     = request.DropOff2;
                taxiInfor.CreateDate   = DateTime.Now;
                taxiInfor.Remark       = request.Remark;

                var resultRequest = new Taxi_RequestDao().InsertOrUpdateRequest(taxiInfor);
                // Insert personal infor
                var checkInsertDetail = true;

                if (request.ListVisitorCSV != "" && request.ListVisitorCSV != null)
                {
                    System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "\\TempCSV.csv", request.ListVisitorCSV, System.Text.Encoding.UTF8);
                    List <CSVModel> values = System.IO.File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "\\TempCSV.csv")
                                             .Skip(1)
                                             .Select(v => FromCsv(v))
                                             .ToList();
                    foreach (var item in values)
                    {
                        if (checkInsertDetail == true)
                        {
                            tbl_Taxi_User_Infor user = new tbl_Taxi_User_Infor();
                            user.Name                  = item.VisitorName;
                            user.EmployeeId            = item.NationalId;
                            user.SLM_Name              = item.CompanyName;
                            user.Taxi_Request_Infor_Id = request.Id;
                            user.Remark                = item.Remark;

                            user.Taxi_Request_Infor_Id = request.Id;
                            // Two record if register dropoff 2
                            if (request.DropOff2 != "" && request.DropOff2 != null)
                            {
                                user.Process      = 1;
                                checkInsertDetail = new Taxi_UserDao().InsertOrUpdateUser(user);
                                user.Process      = 2;
                            }
                            checkInsertDetail = new Taxi_UserDao().InsertOrUpdateUser(user);
                        }
                    }
                }
                else
                {
                    foreach (var item in request.Visitor)
                    {
                        if (checkInsertDetail == true)
                        {
                            item.Taxi_Request_Infor_Id = request.Id;
                            // Two record if register dropoff 2
                            if (request.DropOff2 != "" && request.DropOff2 != null)
                            {
                                item.Process      = 1;
                                checkInsertDetail = new Taxi_UserDao().InsertOrUpdateUser(item);
                                item.Process      = 2;
                            }
                            checkInsertDetail = new Taxi_UserDao().InsertOrUpdateUser(item);
                        }
                    }
                }

                // Insert approval infor
                tbl_Taxi_Approval_Infor approval = new tbl_Taxi_Approval_Infor();
                approval.Request_Id     = (Guid)request.Id;
                approval.DepartmentName = mEmployee.employee.departmentName;
                approval.Process        = 1;
                approval.State          = 0;
                approval.UpdateDate     = DateTime.Now;

                var resultApproval = new Taxi_ApprovalDao().InsertOrUpdateApproval(approval);
                if (resultRequest == true && resultApproval == true && checkInsertDetail == true)
                {
                    Notification("Success", "Create request successfully", MyConstants.NOTIFY_SUCCESS);
                    return(RedirectToAction("Index", "Home", new { type = 0 }));
                }
                else
                {
                    //Rollback - delete when failure
                    var approvalDeleteResult = new Taxi_ApprovalDao().RemoveApprovalByRequestId(request.Id);
                    var userDeleteResult     = new Taxi_UserDao().RemoveUserByRequestId(request.Id);
                    var requestDeleteResult  = new Taxi_RequestDao().RemoveRequest(request.Id);
                    WriteLogError.Write("Insert Request Failure: ", "Request: " + resultRequest + " Visitor: " + checkInsertDetail + " Approval: " + resultApproval);
                    WriteLogError.Write("Rollback Request Failure: ", "Request: " + requestDeleteResult + " Visitor: " + userDeleteResult + " Approval: " + approvalDeleteResult);
                    Notification("False", "Create request failure, Please recheck all information!", MyConstants.NOTIFY_ERROR);
                }
            }
            catch (Exception ex)
            {
                Notification("False", "Create request failure, error: " + ex.ToString(), MyConstants.NOTIFY_ERROR);
            }
            return(RedirectToAction("CreateRequest", "Request"));
        }