Beispiel #1
0
        public ActionResult Login(UserModel user, string returnUrl)
        {
            var nationalCriminalsWcf = new NationalCriminalSvcClient();

            var userProxy = Mapper.MapUserModelToUserProxy(user);

            //Retreive user from database
            var userInstance = nationalCriminalsWcf.GetUserInstanceFromDb(userProxy);

            //If exist
            if (userInstance != null)
            {
                //Set Auth cookie
                var userAuthCookie = userInstance.UserName + ":" + userInstance.Email;


                //We can define custom Iprinicipal class to store email
                FormsAuthentication.SetAuthCookie(userAuthCookie, false);

                if (ModelState.IsValid && Url.IsLocalUrl(returnUrl))
                {
                    return(Redirect(returnUrl));
                }

                return(RedirectToAction("Search", "Criminals"));
            }

            ModelState.AddModelError("", "The user name or password provided is incorrect.");

            return(View(user));
        }
        public ActionResult Search(CriminalsSearchModel searchModel)
        {
            #region Validations
            if (searchModel.MaxAge < searchModel.MinAge)
            {
                ModelState.AddModelError("", "Max Age should be bigger than min age");
                return(View(searchModel));
            }
            else if (searchModel.MaxWeight < searchModel.MinWeight)
            {
                ModelState.AddModelError("", "Mac weight should be bigger than min weight ");
                return(View(searchModel));
            }

            else if (searchModel.MaxHeight < searchModel.MinHeight)
            {
                ModelState.AddModelError("", "Max height should be bigger than min height");
                return(View(searchModel));
            }

            else if (!searchModel.IsMale && !searchModel.IsFemale)
            {
                ModelState.AddModelError("", "You should choose either male or female or both of them");
                return(View(searchModel));
            }

            #endregion
            else
            {
                searchModel.MaxResultCount = 20;

                //get logged in user email
                //User.Identity.Name="name:email"
                var email = User.Identity.Name.Split(':')[1];

                //build search filter criteria
                var criminalSearchCriteria = Mapper.MapCriminalSearchModelToCriminalSearchCriteria(searchModel);

                //create new instance of the national criminals service
                var nationalCriminalsSvc = new NationalCriminalSvcClient();

                //Search for criminals
                var result = nationalCriminalsSvc.SearchCrininals(email, criminalSearchCriteria);

                if (result)
                {
                    ViewBag.Result = "Search completed successfully and email will be sent to you";
                }
                else
                {
                    ViewBag.Result = "error occured try again later";
                }

                return(View(searchModel));
            }
        }
        public ActionResult Add(CriminalModel criminal)
        {
            if (ModelState.IsValid)
            {
                //Create new instance of the national criminals wcf
                var nationalCriminalsWcf = new NationalCriminalSvcClient();

                //Adds to database
                var criminalProxy = Mapper.MapCriminalModelToCriminalProxy(criminal);
                nationalCriminalsWcf.AddCriminal(criminalProxy);

                //Redirecto to search action
                return(RedirectToAction("Search"));
            }
            //Show message in case of errors
            ModelState.AddModelError("", "There was an error in register try again later");

            return(View(criminal));
        }
Beispiel #4
0
        public ActionResult Register(UserModel user)
        {
            if (ModelState.IsValid)
            {
                //Create new instance of the service
                var nationalCriminalsWcf = new NationalCriminalSvcClient();

                //create new user proxy instance
                var userProxy = Mapper.MapUserModelToUserProxy(user);

                //Add user to the database
                nationalCriminalsWcf.AddUser(userProxy);


                //Redirect to login action
                return(RedirectToAction("Login"));
            }

            ModelState.AddModelError("", "There was an error in register try again later");

            return(View(user));
        }