public ActionResult Login(LogOnViewModel model)
        {
            if (ModelState.IsValid)
            {
                SGS.Data.EntityFrameworks.User authenticatedUser = UserManager.Instance.Get(model.EmployeeId, model.Password);
                if (authenticatedUser != null)
                {
                    if (model.IsRemember)
                    {
                        HttpCookie cookie = new HttpCookie(appName);
                        cookie.Values.Add("EmployeeId", model.EmployeeId);
                        cookie.Expires = DateHelper.DateTimeNow.AddDays(15);
                        Response.Cookies.Add(cookie);
                    }

                    //MemberManager.Instance.SaveMemberLastLoggedOn(authenticatedUser.MemberId);
                    Session["CurrentUser"] = authenticatedUser;
                    context.SetAuthenticationToken(authenticatedUser.UserId.ToString(), false, authenticatedUser);

                    //additional startup values
                    string[] roles = Roles.GetRolesForUser(authenticatedUser.UserId.ToString());

                    //if (TempData["ReturnUrl"] != null)
                    //    return Redirect("~/Payroll");
                    //else
                    //    return Redirect("~/Payroll");

                    if (TempData["ReturnUrl"] != null)
                    {
                        return(Redirect(HttpUtility.UrlDecode(TempData["ReturnUrl"].ToString())));
                    }
                    else
                    {
                        return(Redirect("~/"));
                    }
                }
                else
                {
                    ViewBag.IsError = true;
                }
            }
            else
            {
                ViewBag.ValidationError = true;
            }

            return(View(model));
        }
Example #2
0
        public ActionResult MyProfile(EmployeeViewModel model, HttpPostedFileBase file)
        {
            EmployeeViewModel updModel = model;

            ViewBag.IsSuccess = false;

            if (ModelState.IsValid)
            {
                SGS.Data.EntityFrameworks.User employee = UserManager.Instance.Get(model.UserId);

                employee.MaritalStatus     = model.MaritalStatus;
                employee.PresentAddress    = model.PresentAddress;
                employee.ProvincialAddress = model.ProvincialAddress;
                employee.LandlineNo        = model.LandLine;
                employee.MobileNo          = model.MobileNo;
                employee.Email             = model.Email;
                employee.Ref_Name          = model.ReferenceName;
                employee.Ref_Relationship  = model.ReferenceRelationship;
                employee.Ref_Address       = model.ReferenceAddress;
                employee.Ref_ContactNo     = model.ReferenceContactNo;
                employee.TaxIdNo           = model.TaxIdNo;
                employee.SSSNo             = model.SSSNo;
                employee.HDMFNo            = model.HDMFNo;
                employee.PhilHealthNo      = model.PhilHealthNo;
                employee.ModifiedBy        = UserHelper.CurrentUser.EmployeeId;


                if (file != null)
                {
                    string filename = "p_" + Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
                    string pic      = System.IO.Path.GetFileName(filename);
                    string path     = System.IO.Path.Combine(
                        Server.MapPath(ConfigurationManager.AppSettings["UploadPath"].ToString()), pic);

                    file.SaveAs(path);

                    using (MemoryStream ms = new MemoryStream())
                    {
                        file.InputStream.CopyTo(ms);
                        byte[] array = ms.GetBuffer();
                    }

                    employee.Picture = filename;
                }

                try
                {
                    updModel        = EmployeeHelper.Get(UserManager.Instance.SaveUser(employee));
                    ViewBag.Success = true;
                }
                catch (Exception ex)
                {
                    ViewBag.SysError = ex.Message;
                }
            }
            else
            {
                ViewBag.Error = true;
            }

            return(View(updModel));
        }
        public ActionResult Record(EmployeeViewModel model, HttpPostedFileBase file)
        {
            EmployeeViewModel updModel = model;

            ViewBag.IsSuccess = false;
            SetDropdownFields();

            if (ModelState.IsValid)
            {
                SGS.Data.EntityFrameworks.User employee = new SGS.Data.EntityFrameworks.User();
                employee.UserId            = model.UserId;
                employee.FirstName         = model.FirstName;
                employee.MiddleName        = model.MiddleName;
                employee.LastName          = model.LastName;
                employee.NickName          = model.NickName;
                employee.Gender            = model.Gender;
                employee.MaritalStatus     = model.MaritalStatus;
                employee.DateOfBirth       = model.DateOfBirth.Value;
                employee.PlaceOfBirth      = model.PlaceOfBirth;
                employee.PresentAddress    = model.PresentAddress;
                employee.ProvincialAddress = model.ProvincialAddress;
                employee.LandlineNo        = model.LandLine;
                employee.MobileNo          = model.MobileNo;
                employee.Email             = model.Email;
                employee.Nationality       = model.Nationality;
                employee.Ref_Name          = model.ReferenceName;
                employee.Ref_Relationship  = model.ReferenceRelationship;
                employee.Ref_Address       = model.ReferenceAddress;
                employee.Ref_ContactNo     = model.ReferenceContactNo;
                employee.TaxIdNo           = model.TaxIdNo;
                employee.SSSNo             = model.SSSNo;
                employee.HDMFNo            = model.HDMFNo;
                employee.PhilHealthNo      = model.PhilHealthNo;
                employee.RoleId            = model.RoleId;
                employee.Status            = model.Status;
                employee.EmploymentType    = model.EmploymentType;
                employee.Position          = model.Position;
                employee.Client            = model.Client;
                employee.DateHired         = model.DateHired;

                if (employee.UserId == 0)
                {
                    //employee.Password = EncryptionManager.encrypt(ConfigurationManager.AppSettings["DefaultPassword"].ToString());
                    employee.Password  = ConfigurationManager.AppSettings["DefaultPassword"].ToString();
                    employee.CreatedBy = UserHelper.CurrentUser.EmployeeId;
                }
                else
                {
                    employee.ModifiedBy = UserHelper.CurrentUser.EmployeeId;
                }


                if (file != null)
                {
                    string filename = "p_" + Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
                    string pic      = System.IO.Path.GetFileName(filename);
                    string path     = System.IO.Path.Combine(
                        Server.MapPath(ConfigurationManager.AppSettings["UploadPath"].ToString()), pic);

                    file.SaveAs(path);

                    using (MemoryStream ms = new MemoryStream())
                    {
                        file.InputStream.CopyTo(ms);
                        byte[] array = ms.GetBuffer();
                    }

                    employee.Picture = filename;
                }

                try
                {
                    updModel        = EmployeeHelper.Get(UserManager.Instance.SaveUser(employee));
                    ViewBag.Success = true;
                }
                catch (Exception ex)
                {
                    ViewBag.SysError = ex.Message;
                }
            }
            else
            {
                ViewBag.Error = true;
            }

            return(View(updModel));
        }