Exemplo n.º 1
0
        public EmployeeDetailModels GetDetail(string ID)
        {
            EmployeeDetailModels item = new EmployeeDetailModels();

            try
            {
                EmployeeRequest paraBody = new EmployeeRequest();
                paraBody.ID = ID;
                var     result     = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.EmployeeAPIGetDetail, null, paraBody);
                dynamic data       = result.Data;
                var     lstDataRaw = data["EmployeeDetail"];
                var     lstObject  = JsonConvert.SerializeObject(lstDataRaw);
                item = JsonConvert.DeserializeObject <EmployeeDetailModels>(lstObject);
                if (item != null)
                {
                    item.Birthday    = CommonHelper.ConvertToLocalTime(item.Birthday);
                    item.HiredDate   = CommonHelper.ConvertToLocalTime(item.HiredDate);
                    item.ExpiredDate = CommonHelper.ConvertToLocalTime(item.ExpiredDate);
                }
                NSLog.Logger.Info("Employee_GetDetail", item);

                return(item);
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("Employee_GetDetail_Fail", e);
                return(item);
            }
        }
        public ActionResult Index(FormCollection form, EmployeeDetailModels viewModel)
        {
            string funSearchValue = form["searchValue"].ToString();
            string funPageIndex   = form["hidePageIndex"].ToString();

            GetBindData(funSearchValue, funPageIndex, viewModel);
            return(View(viewModel));
        }
Exemplo n.º 3
0
        public ActionResult Create()
        {
            EmployeeDetailModels model = new EmployeeDetailModels();

            model.GetListRole(CurrentUser.RoleLevel);
            model.ListRole    = model.ListRole.Where(w => w.Value != CurrentUser.RoleID).ToList();
            model.CreateUser  = CurrentUser.UserId;
            model.ListCountry = _factory.GetListCountry();
            //get local country
            model.Country = model.ListCountry.Where(ww => ww.Alpha2Code == CurrentCountryCode).Select(ss => ss.Name).FirstOrDefault();
            return(View(model));
        }
Exemplo n.º 4
0
        // GET: Profile
        //public ActionResult Index()
        //{
        //    if (Session["User"] == null)
        //        return RedirectToAction("Index", "Home");
        //    UserModels user = new UserModels();

        //    return View(CurrentUser);
        //}

        public EmployeeDetailModels GetDetail(string id)
        {
            try
            {
                EmployeeDetailModels model = _factory.GetDetail(id);
                return(model);
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("GetDetail error: ", ex);
                return(null);
            }
        }
Exemplo n.º 5
0
        public PartialViewResult Edit(string id)
        {
            EmployeeDetailModels model = GetDetail(id);

            model.GetListRole(CurrentUser.RoleLevel);
            // Current user can not change role
            if (model.RoleID == CurrentUser.RoleID)
            {
                model.ListRole = model.ListRole.Where(w => w.Value == CurrentUser.RoleID).ToList();
            }
            else
            {
                model.ListRole = model.ListRole.Where(w => w.Value != CurrentUser.RoleID).ToList();
            }
            model.CreateUser  = CurrentUser.UserId;
            model.ListCountry = _factory.GetListCountry();
            return(PartialView("_Edit", model));
        }
Exemplo n.º 6
0
        public bool CreateOrEdit(EmployeeDetailModels model, ref string msg)
        {
            try
            {
                EmployeeRequest paraBody = new EmployeeRequest();

                model.Birthday    = CommonHelper.ConvertToUTCTime(model.Birthday);
                model.HiredDate   = CommonHelper.ConvertToUTCTime(model.HiredDate);
                model.ExpiredDate = CommonHelper.ConvertToUTCTime(model.ExpiredDate);

                paraBody.EmployeeDetail = model;
                paraBody.CreatedUser    = model.CreateUser;
                var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.EmployeeAPICreateOrEdit, null, paraBody);
                if (result != null)
                {
                    if (result.Success)
                    {
                        return(true);
                    }
                    else
                    {
                        msg = result.Message;
                        //msg = Commons.ErrorMsg;
                        NSLog.Logger.Info("Employee_CreateOrEdit", result.Message);
                        return(false);
                    }
                }
                else
                {
                    NSLog.Logger.Info("Employee_CreateOrEdit", result);
                    return(false);
                }
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("Employee_CreateOrEdit_Fail", e);
                return(false);
            }
        }
Exemplo n.º 7
0
 public bool ChangePassword(EmployeeDetailModels model, ref string msg, string mec, string userid)
 {
     try
     {
         EmployeeChangePasswordRequest paraBody = new EmployeeChangePasswordRequest();
         paraBody.CreatedUser = userid;
         paraBody.ID          = model.ID;
         paraBody.OldPassword = CommonHelper.GetSHA512(model.OldPassword);
         paraBody.NewPassword = CommonHelper.GetSHA512(model.NewPassword);
         var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.ChangePassword, null, paraBody);
         if (result != null)
         {
             if (result.Success)
             {
                 return(true);
             }
             else
             {
                 msg = result.Message;
                 //msg = Commons.ErrorMsg;
                 NSLog.Logger.Info("Employee_ChangePassword", result.Message);
                 return(false);
             }
         }
         else
         {
             NSLog.Logger.Info("Employee_ChangePassword", result);
             return(false);
         }
     }
     catch (Exception e)
     {
         msg = e.ToString();
         NSLog.Logger.Error("Employee_ChangePassword error: ", e);
         return(false);
     }
 }
        public PartialViewResult GetBindData(string funSearchValue, string funPageIndex, EmployeeDetailModels viewModel)
        {
            List <listEmployeeDetail> empList = new List <listEmployeeDetail>();

            empList = edModel.ReListEmployeeDetail();
            if (!(string.IsNullOrWhiteSpace(funSearchValue)))
            {
                empList = empList.Where(x => x.lEmpIndex.Contains(funSearchValue) || x.lEmpName.Contains(funSearchValue) ||
                                        x.lEmpEmail.Contains(funSearchValue) || x.lEmpMobile.Contains(funSearchValue) ||
                                        x.lEmpPhone.Contains(funSearchValue) || x.lEmpNotation.Contains(funSearchValue) ||
                                        x.lEmpRemark.Contains(funSearchValue) || x.lEmpJoinDate.Contains(funSearchValue) ||
                                        x.lEmpLeaveDate.Contains(funSearchValue)).ToList();
            }
            viewModel.listEmployeeDetail = empList;
            viewModel.valSumDataCount    = empList.Count.ToString();
            viewModel.valPageDataCount   = "30";
            viewModel.valSumPageCount    = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(viewModel.valSumDataCount) / Convert.ToDecimal(viewModel.valPageDataCount))).ToString();
            viewModel.valPageIndex       = (ViewBag.valPageIndex == null) ? "1" : viewModel.valPageIndex;
            viewModel.valPageIndex       = funPageIndex;
            ViewBag.valPageIndex         = viewModel.valPageIndex;
            ViewBag.valShowDetail        = ViewBag.valPageIndex;
            ViewBag.valSumDataCount      = viewModel.valSumDataCount;
            ViewBag.valPageDataCount     = viewModel.valPageDataCount;
            ViewBag.valSumPageCount      = viewModel.valSumPageCount;
            return(PartialView("List", viewModel));
        }
 // GET: EmployeeDetail
 public ActionResult Index(EmployeeDetailModels viewModel)
 {
     GetBindData("", "1", viewModel);
     return(View(viewModel));
 }
Exemplo n.º 10
0
        public ActionResult ChangePassword(EmployeeDetailModels model)
        {
            listStorePropertiesReject = new List <string>();
            listStorePropertiesReject.Add("ZipCode");
            listStorePropertiesReject.Add("Country");
            listStorePropertiesReject.Add("Phone");
            PropertyReject();

            string _newPassword = "", _oldPassword = "", _comfirmPassword = "";

            try
            {
                _newPassword     = model.NewPassword;
                _oldPassword     = model.OldPassword;
                _comfirmPassword = model.ConfirmPassword;
                if (string.IsNullOrEmpty(model.OldPassword))
                {
                    ModelState.AddModelError("OldPassword", "Current Password field is required");
                }

                if (string.IsNullOrEmpty(model.NewPassword))
                {
                    ModelState.AddModelError("NewPassword", "New Password field is required");
                }

                if (string.IsNullOrEmpty(model.ConfirmPassword))
                {
                    ModelState.AddModelError("ConfirmPassword", "Confirm New Password field is required");
                }

                if (!model.NewPassword.Equals(model.ConfirmPassword))
                {
                    ModelState.AddModelError("ConfirmPassword", "Confirm New Password and new password incorrect");
                }

                if (!ModelState.IsValid)
                {
                    model                 = GetDetail(model.ID);
                    model.OldPassword     = _oldPassword;
                    model.NewPassword     = _newPassword;
                    model.ConfirmPassword = _comfirmPassword;
                    Response.StatusCode   = (int)HttpStatusCode.BadRequest;
                    return(View(model));
                }

                string msg    = "";
                string mec    = CurrentUser.OrganizationId;
                string useid  = CurrentUser.UserId;
                var    result = _factory.ChangePassword(model, ref msg, mec, useid);
                if (result)
                {
                    return(RedirectToAction("Logout", "Home", new { area = "" }));
                }
                else
                {
                    ModelState.AddModelError("ConfirmPassword", msg);
                    model                 = GetDetail(model.ID);
                    model.OldPassword     = _oldPassword;
                    model.NewPassword     = _newPassword;
                    model.ConfirmPassword = _comfirmPassword;
                    /*===*/
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Employee_Change Password Error: ", ex);
                ModelState.AddModelError("ConfirmPassword", ex.Message);
                model                 = GetDetail(model.ID);
                model.OldPassword     = _oldPassword;
                model.NewPassword     = _newPassword;
                model.ConfirmPassword = _comfirmPassword;
                Response.StatusCode   = (int)HttpStatusCode.BadRequest;
                return(View(model));
            }
        }
Exemplo n.º 11
0
        public ActionResult ChangePassword()
        {
            EmployeeDetailModels model = GetDetail(CurrentUser.UserId);

            return(View(model));
        }
Exemplo n.º 12
0
        public ActionResult Create(EmployeeDetailModels model)
        {
            try
            {
                if (model.PictureUpload != null && !Commons.ImageExtendFiler.Contains(model.PictureUpload.ContentType))
                {
                    ModelState.AddModelError("PictureUpload", Commons.ErrorMsgFilterImage);
                }

                if (!ModelState.IsValid)
                {
                    if ((ModelState["PictureUpload"]) != null && (ModelState["PictureUpload"]).Errors.Count > 0)
                    {
                        model.ImageURL = "";
                    }
                    model.ListCountry   = _factory.GetListCountry();
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(View(model));
                }

                //=============================
                model.Email = model.Email.ToLower();
                byte[] photoByte = null;
                if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0)
                {
                    Byte[] imgByte = new Byte[model.PictureUpload.ContentLength];
                    model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength);
                    model.PictureByte   = imgByte;
                    model.ImageURL      = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName);
                    model.PictureUpload = null;
                    photoByte           = imgByte;
                }
                else
                {
                    if (!string.IsNullOrEmpty(model.ImageURL))
                    {
                        model.ImageURL = model.ImageURL.Replace(Commons.PublicImages, "").Replace(Commons.Image200_200, "");
                    }
                }
                string msg = "";
                var    tmp = model.PictureByte;
                model.PictureByte = null;
                bool result = _factory.CreateOrEdit(model, ref msg);
                if (result)
                {
                    model.PictureByte = tmp;
                    ////Save Image on Server
                    if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null)
                    {
                        var          originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", Server.MapPath(@"\")));
                        var          path = string.Format("{0}{1}", originalDirectory, model.ImageURL);
                        MemoryStream ms   = new MemoryStream(photoByte, 0, photoByte.Length);
                        ms.Write(photoByte, 0, photoByte.Length);
                        System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true);
                        ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte);
                        model.PictureByte = photoByte;
                        FTP.Upload(model.ImageURL, model.PictureByte);
                        ImageHelper.Me.TryDeleteImageUpdated(path);
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //return RedirectToAction("Create");
                    ModelState.AddModelError("Error", msg);
                    model.ImageURL    = "";
                    model.ListCountry = _factory.GetListCountry();
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Employee_Create: ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
Exemplo n.º 13
0
        public new PartialViewResult View(string id)
        {
            EmployeeDetailModels model = GetDetail(id);

            return(PartialView("_View", model));
        }
Exemplo n.º 14
0
        public PartialViewResult Delete(string id)
        {
            EmployeeDetailModels model = GetDetail(id);

            return(PartialView("_Delete", model));
        }