}//..End User

        public ActionResult AddCollectionUser()
        {
            if (Session["Email"] != null && Session["UserID"] != null)
            {
                ViewBag.ActiveMenu = "AddUser";
                AddCollectionUserModel _AddUserModel = new AddCollectionUserModel();
                DataSet dbInitial = _UsersManagementService.LoadDetail(Session["Email"].ToString(), "OPERATOR");
                _AddUserModel.Position = dbInitial.Tables[0].AsEnumerable().Select(row => new PositionModel
                {
                    PositionId   = Convert.ToInt32(row["GR_CODE"]),
                    PositionName = Convert.ToString(row["DESCRIPTION"])
                });
                _AddUserModel.Street = dbInitial.Tables[1].AsEnumerable().Select(row => new StreetModel
                {
                    StreetId   = Convert.ToInt32(row["STREET_CODE"]),
                    StreetName = Convert.ToString(row["STREET_NAME"])
                });
                _AddUserModel.sex = _SystemTools.GetGender();
                return(View(_AddUserModel));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }//..End User
 public ActionResult CreateCollectionUser(AddCollectionUserModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _UsersManagementService.CreateCollectionUser(Session["Email"].ToString(), model);
             TempData["Success"] = "Sucess";
             return(RedirectToAction("AddUser"));
         }
         catch (Exception ex)
         {
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             ModelState.AddModelError("", ex.Message);
             TempData["Fail"] = "Fail";
             return(View("AddUser", model));
         }
     }
     else
     {
         TempData["ModelsError"] = "Error";
         return(RedirectToAction("AddUser"));
     }
 }//..Create User
Example #3
0
        //Save use to the database
        public int CreateCollectionUser(string sUserId, AddCollectionUserModel entity)
        {
            using (SqlConnection conn = new SqlConnection(DBCon))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("SaveUser", conn);//call Stored Procedure
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Firstname", entity.Firstname);
                cmd.Parameters.AddWithValue("@Middlename", entity.Middlename);
                cmd.Parameters.AddWithValue("@Lastname", entity.Lastname);
                cmd.Parameters.AddWithValue("@Gender", entity.Gender);
                cmd.Parameters.AddWithValue("@Email", entity.Email);
                cmd.Parameters.AddWithValue("@Phone", entity.Phone);
                cmd.Parameters.AddWithValue("@Position", entity.PositionId);
                cmd.Parameters.AddWithValue("@Password", _SystemTools.EncryptPass(entity.Password));
                cmd.Parameters.AddWithValue("@AreaCode", entity.StreetId);
                cmd.Parameters.AddWithValue("@Flag", "Collection");
                cmd.Parameters.AddWithValue("@UserId", sUserId);

                int rs = cmd.ExecuteNonQuery();

                return(rs);
            }
        }