Ejemplo n.º 1
0
        public ActionResult Index(EmployeeViewModel model)
        {
            try
            {
                MvcTutorialEntities  db          = new MvcTutorialEntities();
                List <tblDepartment> departments = db.tblDepartments.ToList();
                ViewBag.DeparmentList = new SelectList(departments, "DepartmentId", "DepartmentName");

                if (model.EmployeeID > 0)
                {   //update
                    tblEmployee emp = db.tblEmployees.SingleOrDefault(x => x.EmployeeID == model.EmployeeID && x.isDeleted == false);

                    emp.DepartmentId = model.DepartmentId;
                    emp.Name         = model.Name;
                    emp.Address      = model.Address;
                    db.SaveChanges();
                }
                else
                {   //insert
                    tblEmployee emp = new tblEmployee();
                    emp.Address      = model.Address;
                    emp.Name         = model.Name;
                    emp.DepartmentId = model.DepartmentId;
                    emp.isDeleted    = false;
                    db.tblEmployees.Add(emp);
                    db.SaveChanges();
                }
                return(View(model));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public ActionResult ChangePassword(UserChangePasswordModelClass modelchangerPasswordData)
        {
            if (ModelState.IsValid)
            {
                using (var database = new MvcTutorialEntities())
                {
                    int UserID = Convert.ToInt32(Session["UserID"]);
                    var verify = database.tblUser.FirstOrDefault(user => user.UserID == UserID && user.Password == modelchangerPasswordData.OldPassword && user.IsActive == true);
                    if (verify != null)
                    {
                        verify.Password = modelchangerPasswordData.NewPassword;
                        database.SaveChanges();

                        ViewBag.SuccessMessage = "Password Change Successfully. Please Re-Login With New Password.";
                        Session.RemoveAll();
                        return(RedirectToAction("Login", "User"));
                    }
                    else
                    {
                        ViewBag.Message = "You have Enter Wrong Old Password.";
                    }
                }
            }

            return(View());
        }
Ejemplo n.º 3
0
        public HttpResponseMessage ChangePassword(UserChangePasswordModelClass modelchangerPasswordData)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var database = new MvcTutorialEntities())
                    {
                        //int UserID = modelchangerPasswordData.UserID;
                        var verify = database.tblUser.FirstOrDefault(user => user.UserID == modelchangerPasswordData.UserID && user.Password == modelchangerPasswordData.OldPassword && user.IsActive == true);
                        if (verify != null)
                        {
                            verify.Password = modelchangerPasswordData.NewPassword;
                            database.SaveChanges();

                            return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.RESETPASSWORD));
                            //ViewBag.SuccessMessage = "Password Change Successfully. Please Re-Login With New Password.";
                        }
                        else
                        {
                            return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.INVALIDPASSWORD));
                            //ViewBag.Message = "You have Enter Wrong Old Password.";
                        }
                    }
                }
                else
                {
                    return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.NODATA));
                }
            }
            catch (Exception ex)
            {
                return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
 public ActionResult DeleteAccount()
 {
     if (Session["UserID"] != null)
     {
         using (var database = new MvcTutorialEntities())
         {
             int UserID = Convert.ToInt32(Session["UserID"]);
             var databaseUserAccount = database.tblUser.Find(UserID);
             if (databaseUserAccount != null)
             {
                 database.tblUser.Remove(databaseUserAccount);
                 Session.RemoveAll();
                 database.SaveChanges();
                 ViewBag.SuccessMessage = "Your Account is Deleted Successfully.";
                 return(RedirectToAction("Registration", "User"));
             }
             else
             {
                 return(RedirectToAction("Index", "Home"));
             }
         }
     }
     else
     {
         return(RedirectToAction("Login", "User"));
     }
 }
        public ActionResult ProfileInfo(UserProfileModelClass modelprofiledData)
        {
            if (ModelState.IsValid)
            {
                using (var database = new MvcTutorialEntities())
                {
                    int UserID       = Convert.ToInt32(Session["UserID"]);
                    var databaseData = database.tblUser.FirstOrDefault(user => user.UserID == UserID && user.IsActive == true);
                    if (databaseData != null)
                    {
                        databaseData.MobileNo     = modelprofiledData.MobileNo;
                        databaseData.EmailAddress = modelprofiledData.EmailAddress;
                        databaseData.Address      = modelprofiledData.Address;

                        database.SaveChanges();

                        ViewBag.SuccessMessage = "Profile Update Successfully.";
                        return(View());
                    }
                    else
                    {
                        ViewBag.Message = "Couldn't Find Your Profile.";
                    }
                }
            }

            return(View());
        }
Ejemplo n.º 6
0
 public HttpResponseMessage DeactivateAccount(int id)
 {
     try
     {
         if (id != 0)
         {
             using (var database = new MvcTutorialEntities())
             {
                 var databaseUserAccount = database.tblUser.Find(id);
                 if (databaseUserAccount != null)
                 {
                     databaseUserAccount.IsActive = false;
                     database.SaveChanges();
                     return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.ACCOUNTDEACTIVATEDSUCCESSFULLY));
                 }
                 else
                 {
                     return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.DATANOTFOUND));
                 }
             }
         }
         else
         {
             return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.NODATA));
         }
     }
     catch (Exception ex)
     {
         return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Ejemplo n.º 7
0
        public HttpResponseMessage CreateNewPassword(UserNewPasswordModelClass modelnewpasswordData)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var db = new MvcTutorialEntities())
                    {
                        var verify = db.tblUser.Find(modelnewpasswordData.UserID);
                        if (verify != null)
                        {
                            verify.Password = modelnewpasswordData.NewPassword;
                            db.SaveChanges();

                            return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.NEWPASSWORD));
                        }
                        else
                        {
                            return(this.GenerateResponse(false, HttpStatusCode.Unauthorized, Constants.UNOTHORIZED));
                        }
                    }
                }
                else
                {
                    return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.NODATA));
                }
            }
            catch (Exception ex)
            {
                return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Ejemplo n.º 8
0
        public JsonResult ImageUpload(ProductViewModel model)
        {
            MvcTutorialEntities db = new MvcTutorialEntities();
            int imageId            = 0;
            var file = model.ImageFile;

            byte[] imagebyte = null;
            if (file != null)
            {
                file.SaveAs(Server.MapPath("/UploadedImage/" + file.FileName));

                BinaryReader reader = new BinaryReader(file.InputStream);
                imagebyte = reader.ReadBytes(file.ContentLength);

                ImageStore img = new ImageStore();

                img.ImageName = file.FileName;
                img.ImageByte = imagebyte;
                img.ImagePath = "/UploadedImage/" + file.FileName;
                img.IsDeleted = false;


                db.ImageStores.Add(img);
                db.SaveChanges();
                imageId = img.ImageId;
            }
            if (model.ImageUrl != null)
            {
                imagebyte = DownloadImage(model.ImageUrl);

                ImageStore img = new ImageStore();

                img.ImageName = "Abc";
                img.ImageByte = imagebyte;
                img.ImagePath = model.ImageUrl;
                img.IsDeleted = false;


                db.ImageStores.Add(img);
                db.SaveChanges();
                imageId = img.ImageId;
            }

            return(Json(imageId, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
0
        public ActionResult DeleteEmployee(int employeId)
        {
            MvcTutorialEntities db       = new MvcTutorialEntities();
            Employee            employee = db.Employee.Where(e => e.Id == employeId).FirstOrDefault();

            db.Employee.Remove(employee);
            db.SaveChanges();
            return(View());
        }
Ejemplo n.º 10
0
        public HttpResponseMessage ProfileInfo(UserProfileModelClass modelprofiledData)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var database = new MvcTutorialEntities())
                    {
                        // this validation is use when browser will disable javasript.
                        if (database.tblUser.Any(email => email.EmailAddress == modelprofiledData.EmailAddress && email.EmailAddress != modelprofiledData.EmailAddress))
                        {
                            return(this.GenerateResponse(false, HttpStatusCode.Found, Constants.EMAILALREADYEXISTS));
                        }
                        else if (database.tblUser.Any(Mobileno => Mobileno.MobileNo == modelprofiledData.MobileNo && Mobileno.MobileNo != modelprofiledData.MobileNo))
                        {
                            return(this.GenerateResponse(false, HttpStatusCode.Found, Constants.MOBILEALREADYEXISTS));
                        }
                        else
                        {
                            var databaseData = database.tblUser.FirstOrDefault(user => user.UserID == modelprofiledData.UserID && user.IsActive == true);
                            if (databaseData != null)
                            {
                                databaseData.MobileNo     = modelprofiledData.MobileNo;
                                databaseData.EmailAddress = modelprofiledData.EmailAddress;
                                databaseData.Address      = modelprofiledData.Address;

                                database.Entry(databaseData).State = System.Data.Entity.EntityState.Modified;
                                database.SaveChanges();

                                return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.PROFILEUPDATE));
                                //ViewBag.SuccessMessage = "Profile Update Successfully.";
                                //return View();
                            }
                            else
                            {
                                return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.DATANOTFOUND));
                                //ViewBag.Message = "Couldn't Find Your Profile.";
                            }
                        }
                    }
                }
                else
                {
                    return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.NODATA));
                }
            }
            catch (Exception ex)
            {
                return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Ejemplo n.º 11
0
        public HttpResponseMessage ActivateAccount(UserActiveAccountClass modeluseractiveaccount)
        {
            try
            {
                using (var database = new MvcTutorialEntities())
                {
                    switch (modeluseractiveaccount.Action)
                    {
                    case "MobileVerify":
                        var verifyMobile = database.tblUser.FirstOrDefault(user => user.MobileNo == modeluseractiveaccount.MobileNo);
                        if (verifyMobile != null)
                        {
                            if (verifyMobile.IsActive == false)
                            {
                                return(this.GenerateResponse(true, HttpStatusCode.OK, verifyMobile.UserID));
                            }
                            else
                            {
                                return(this.GenerateResponse(false, HttpStatusCode.Conflict, Constants.ACCOUNTDEALREADYACTIVE));
                            }
                        }
                        else
                        {
                            return(this.GenerateResponse(false, HttpStatusCode.Conflict, Constants.MOBILENOTEXISTS));
                        }

                    case "PasswordVerify":
                        var verifyPassword = database.tblUser.FirstOrDefault(user => user.UserID == modeluseractiveaccount.UserID && user.Password == modeluseractiveaccount.Password && user.IsActive == false);
                        if (verifyPassword != null)
                        {
                            verifyPassword.IsActive = true;
                            database.SaveChanges();
                            return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.ACCOUNTACTIVATEDSUCCESSFULLY));
                        }
                        else
                        {
                            return(this.GenerateResponse(false, HttpStatusCode.Conflict, Constants.INVALIDPASSWORD));
                        }

                    default:
                        return(this.GenerateResponse(false, HttpStatusCode.NotAcceptable, Constants.INVALID));
                    }
                }
            }
            catch (Exception ex)
            {
                return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Ejemplo n.º 12
0
        public JsonResult DeleteEmployee(int EmployeeId)
        {
            MvcTutorialEntities db = new MvcTutorialEntities();
            bool result            = false;

            tblEmployee emp = db.tblEmployees.SingleOrDefault(x => x.isDeleted == false && x.EmployeeID == EmployeeId);

            if (emp != null)
            {
                emp.isDeleted = true;
                db.SaveChanges();
                result = true;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 13
0
        public ActionResult RegisterUser(RegistrationViewModel model)
        {
            MvcTutorialEntities db = new MvcTutorialEntities();

            tblSiteUser siteUser = new tblSiteUser();

            siteUser.UserName = model.UserName;
            siteUser.EmailId  = model.EmailId;
            siteUser.Address  = model.Address;
            siteUser.Password = model.Password;
            siteUser.RoleId   = 3;

            db.tblSiteUsers.Add(siteUser);
            db.SaveChanges();

            return(View());
        }
Ejemplo n.º 14
0
        public HttpResponseMessage Registration(UserRegistrationModelClass modelUserRegisterData)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var database = new MvcTutorialEntities())
                    {
                        // this validation is use when browser will disable javasript.
                        if (database.tblUser.Any(email => email.EmailAddress == modelUserRegisterData.EmailAddress))
                        {
                            return(this.GenerateResponse(false, HttpStatusCode.Found, Constants.EMAILALREADYEXISTS));
                        }
                        else if (database.tblUser.Any(Mobileno => Mobileno.MobileNo == modelUserRegisterData.MobileNo))
                        {
                            return(this.GenerateResponse(false, HttpStatusCode.Found, Constants.MOBILEALREADYEXISTS));
                        }
                        else
                        {
                            tblUser dbobjectuser = new tblUser();
                            dbobjectuser.UserName          = modelUserRegisterData.UserName;
                            dbobjectuser.MobileNo          = modelUserRegisterData.MobileNo;
                            dbobjectuser.EmailAddress      = modelUserRegisterData.EmailAddress;
                            dbobjectuser.Password          = modelUserRegisterData.Password;
                            dbobjectuser.Address           = modelUserRegisterData.Address;
                            dbobjectuser.IsActive          = true;
                            dbobjectuser.AccountCreateDate = System.DateTime.Now;

                            database.tblUser.Add(dbobjectuser);
                            database.SaveChanges();
                            return(this.GenerateResponse(true, HttpStatusCode.OK, Constants.ACCOUNTCREATEDSUCCESSFULLY));
                        }
                    }
                }
                else
                {
                    return(this.GenerateResponse(false, HttpStatusCode.NotFound, Constants.INVALID));
                }
            }
            catch (Exception ex)
            {
                return(this.GenerateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public ActionResult CreateNewPassword(UserNewPasswordModelClass modelnewpasswordData)
        {
            if (ModelState.IsValid)
            {
                using (var db = new MvcTutorialEntities())
                {
                    var UserID = Convert.ToInt32(Session["ForgotPassword"]);
                    var verify = db.tblUser.Find(UserID);
                    if (verify != null)
                    {
                        verify.Password = modelnewpasswordData.NewPassword;
                        db.SaveChanges();
                        ViewBag.SuccessMessage = "New Password Created Successfully. Please Re-Login with New Password.";
                        Session.RemoveAll();
                        return(Json(new { msg = "success" }, JsonRequestBehavior.AllowGet));

                        //return RedirectToAction("Login", "User");
                    }
                }
            }
            return(View());
        }
        public ActionResult Registration(UserRegistrationModelClass modelUserRegister)
        {
            if (ModelState.IsValid)
            {
                using (var database = new MvcTutorialEntities())
                {
                    tblUser dbobjectuser = new tblUser();
                    dbobjectuser.UserName          = modelUserRegister.UserName;
                    dbobjectuser.MobileNo          = modelUserRegister.MobileNo;
                    dbobjectuser.EmailAddress      = modelUserRegister.EmailAddress;
                    dbobjectuser.Password          = modelUserRegister.Password;
                    dbobjectuser.Address           = modelUserRegister.Address;
                    dbobjectuser.IsActive          = true;
                    dbobjectuser.AccountCreateDate = System.DateTime.Now;

                    database.tblUser.Add(dbobjectuser);
                    database.SaveChanges();
                    ViewBag.SuccessMessage = "Account Created Successfully.";
                }
            }
            return(RedirectToAction("Login", "User"));
        }
Ejemplo n.º 17
0
        public ActionResult DepartmentDropdown(EmployeeViewModel model)
        {
            //if (ModelState.IsValid == true)
            //{
            MvcTutorialEntities db = new MvcTutorialEntities();

            //dropdown
            List <department> departments = db.department.ToList();

            ViewBag.departmentList = new SelectList(departments, "Id", "departmentname");
            //
            Employee employee = new Employee();

            employee.name         = model.name;
            employee.adress       = model.adress;
            employee.departmentId = model.departmentId;
            db.Employee.Add(employee);
            db.SaveChanges();

            //}


            return(View());
        }