Пример #1
0
        public async Task <ActionResult> Create([Bind(Include = "otherID,otherType,senderName,senderAdress,senderEmail,senderPhoneNumber,recieverName,recieverAdress,recieverEmail,recieverPhoneNumber,destination,price,paid,alreadyPaid,paidRest,weight,height,length,depth,contentDescription,userID")] Other other)
        {
            ViewBag.ReturnUrl = Url.Action("Other");

            if (ModelState.IsValid)
            {
                other.userID      = Int32.Parse(User.Identity.GetUserName().Split('|')[1]);
                other.createdDate = DateTime.Now;
                other.paidRest    = other.price - other.alreadyPaid;
                if (other.senderEmail.Equals(""))
                {
                    other.senderEmail = "*****@*****.**";
                }
                db.Other.Add(other);
                try
                {
                    await db.SaveChangesAsync();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    // Todo Log the error
                }
                return(RedirectToAction("Index", new { Message = NotificationMessage.ManageMessageId.RecordSuccess }));
            }

            return(View(other));
        }
Пример #2
0
        public async Task <ActionResult> ManageUser(USER user)
        {
            ViewBag.ReturnUrl = Url.Action("ManageUser");

            // Remove the useles data column because we dont#t need them to Change the password
            ModelState.Remove("password");
            ModelState.Remove("userName");
            ModelState.Remove("userID");
            ModelState.Remove("email");

            int userId = user.userID;

            //            var errors3 = ModelState
            //.Where(x => x.Value.Errors.Count > 0)
            //.Select(x => new { x.Key, x.Value.Errors })
            //.ToArray();

            if (ModelState.IsValid)
            {
                // Set obligated User Property before updated the changes
                user.password = user.newPassword;
                user.userName = User.Identity.GetUserName().Split('|')[0].ToString();
                user.userID   = Int32.Parse(User.Identity.GetUserName().Split('|')[1]);
                using (FirstCargoDbEntities entities = new FirstCargoDbEntities())
                {
                    USER userToUpdate = entities.USER.SingleOrDefault(u => u.userName == user.userName);
                    var  hashCode     = userToUpdate.vCode;
                    //Password Hasing Process Call Helper Class Method
                    var encodingPasswordString = RegistrationLoginHelper.EncodePassword(user.oldPassword, hashCode);

                    if (encodingPasswordString.Equals(userToUpdate.password))
                    {
                        //Check Login Detail User Name Or Password
                        var query = (from s in entities.USER where (s.userName == user.userName || s.email == user.userName) && s.password.Equals(encodingPasswordString) select s).FirstOrDefault();

                        if (query != null)
                        {
                            var password = RegistrationLoginHelper.EncodePassword(user.newPassword, hashCode);
                            userToUpdate.oldPassword          = userToUpdate.password;
                            userToUpdate.password             = userToUpdate.newPassword = userToUpdate.confirmPassword = password;
                            userToUpdate.passwordChangedDates = DateTime.Now;

                            db.Entry(userToUpdate).State = EntityState.Modified;
                            try
                            {
                                await db.SaveChangesAsync();
                            }
                            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                            {
                                // Todo Log the error
                            }
                        }
                    }
                }
                return(RedirectToAction("ManageUser", new { Message = NotificationMessage.ManageMessageId.ChangePasswordSuccess }));
            }
            // how form again if there is a failure
            return(View(user));
        }