コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,GroupName")] CompanyGroups companyGroups)
        {
            if (id != companyGroups.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    companyGroups.CompanyID = HttpContext.Session.GetInt32("CompanyID") ?? 0;
                    _context.Update(companyGroups);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CompanyGroupsExists(companyGroups.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(companyGroups));
        }
コード例 #2
0
        public IActionResult AddUser(string returnUrl = null)
        {
            // Initialise groups
            var vm = new AddUserViewModel
            {
                AvailableGroups = CompanyGroups.GetGroups().ToList()
            };

            ViewData["ReturnUrl"] = returnUrl;
            return(View(vm));
        }
コード例 #3
0
        private async Task <EditUserViewModel> BuildEditUserViewModel(ApplicationUser user)
        {
            IList <string> Roles = await _userManager.GetRolesAsync(user);

            Roles = Roles.Where(r => (r == Permission.User.ToString()) || (r == Permission.Admin.ToString())).ToList();

            Permission currentRole = Permission.User;

            // The user doesn't have a role, shouldn't be possible but set them to default user anyways.
            if (Roles.Count == 0)
            {
                currentRole = Permission.User;
            }
            // Must check what permission the user currently has.
            else
            {
                var permissionValues = Enum.GetNames(typeof(Permission));

                foreach (var role in Roles)
                {
                    // Convert the role stored in the database into a type of permission enum.
                    if (permissionValues.Contains(role))
                    {
                        currentRole = (Permission)Enum.Parse(typeof(Permission), role);
                    }
                }
            }

            // Need to get the users' groups from the claims table.
            IList <Claim> userClaims = await _userManager.GetClaimsAsync(user);


            // Filter claims to just groups the user belongs to?
            IList <string> groups = userClaims.Where(c => c.Type == "Group").Select(c => c.Value).ToList();


            // Construct the model, what the user will be able to see and modify.

            var vm = new EditUserViewModel()
            {
                Id              = user.Id,
                PreviousGroups  = new List <string>(),
                AvailableGroups = CompanyGroups.GetGroups().ToList(),
                Username        = user.UserName,
                FirstName       = user.FirstName,
                LastName        = user.LastName,
                IsLocked        = user.IsLocked,
                UserRole        = currentRole,
                SelectedGroups  = groups,
            };


            return(vm);
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("ID,GroupName")] CompanyGroups companyGroups)
        {
            if (ModelState.IsValid)
            {
                companyGroups.CompanyID = HttpContext.Session.GetInt32("CompanyID") ?? 0;
                _context.Add(companyGroups);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(companyGroups));
        }
コード例 #5
0
        public HttpResponseMessage SaveCompanyGroups(CompanyGroups n)
        {
            LogTraceWriter traceWriter = new LogTraceWriter();

            traceWriter.Trace(Request, "0", TraceLevel.Info, "{0}", "SaveCompanyGroups credentials....");
            //DataTable Tbl = new DataTable();
            SqlConnection conn = new SqlConnection();

            try
            {
                //connect to database

                // connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
                conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["btposdb"].ToString();

                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "InsUpdDelCompany";
                cmd.Connection  = conn;

                conn.Open();

                SqlParameter gsa = new SqlParameter();
                gsa.ParameterName = "@active";
                gsa.SqlDbType     = SqlDbType.Int;
                gsa.Value         = n.active;
                cmd.Parameters.Add(gsa);

                SqlParameter gsn = new SqlParameter();
                gsn.ParameterName = "@code";
                gsn.SqlDbType     = SqlDbType.VarChar;
                gsn.Value         = n.code;
                cmd.Parameters.Add(gsn);

                SqlParameter gsab = new SqlParameter();
                gsab.ParameterName = "@desc";
                gsab.SqlDbType     = SqlDbType.VarChar;
                gsab.Value         = n.desc;
                cmd.Parameters.Add(gsab);

                SqlParameter gsac = new SqlParameter("@Id", SqlDbType.Int);
                gsac.Value = n.Id;
                cmd.Parameters.Add(gsac);

                SqlParameter gid = new SqlParameter();
                gid.ParameterName = "@Name";
                gid.SqlDbType     = SqlDbType.VarChar;
                gid.Value         = n.Name;
                cmd.Parameters.Add(gid);


                SqlParameter gad = new SqlParameter();
                gad.ParameterName = "@Address";
                gad.SqlDbType     = SqlDbType.VarChar;
                gad.Value         = n.Address;
                cmd.Parameters.Add(gad);

                SqlParameter gcn = new SqlParameter();
                gcn.ParameterName = "@ContactNo1";
                gcn.SqlDbType     = SqlDbType.VarChar;
                gcn.Value         = n.ContactNo1;
                cmd.Parameters.Add(gcn);

                SqlParameter gcn1 = new SqlParameter();
                gcn1.ParameterName = "@ContactNo2";
                gcn1.SqlDbType     = SqlDbType.VarChar;
                gcn1.Value         = n.ContactNo2;
                cmd.Parameters.Add(gcn1);

                SqlParameter gfx = new SqlParameter();
                gfx.ParameterName = "@Fax";
                gfx.SqlDbType     = SqlDbType.VarChar;
                gfx.Value         = n.Fax;
                cmd.Parameters.Add(gfx);

                SqlParameter gem = new SqlParameter();
                gem.ParameterName = "@EmailId";
                gem.SqlDbType     = SqlDbType.VarChar;
                gem.Value         = n.EmailId;
                cmd.Parameters.Add(gem);

                SqlParameter gtl = new SqlParameter();
                gtl.ParameterName = "@Title";
                gtl.SqlDbType     = SqlDbType.VarChar;
                gtl.Value         = n.Title;
                cmd.Parameters.Add(gtl);

                SqlParameter gcp = new SqlParameter();
                gcp.ParameterName = "@Caption";
                gcp.SqlDbType     = SqlDbType.VarChar;
                gcp.Value         = n.Caption;
                cmd.Parameters.Add(gcp);

                SqlParameter gct = new SqlParameter();
                gct.ParameterName = "@Country";
                gct.SqlDbType     = SqlDbType.VarChar;
                gct.Value         = n.Country;
                cmd.Parameters.Add(gct);

                SqlParameter gzp = new SqlParameter();
                gzp.ParameterName = "@ZipCode";
                gzp.SqlDbType     = SqlDbType.VarChar;
                gzp.Value         = n.ZipCode;
                cmd.Parameters.Add(gzp);

                SqlParameter gst = new SqlParameter();
                gst.ParameterName = "@State";
                gst.SqlDbType     = SqlDbType.VarChar;
                gst.Value         = n.State;
                cmd.Parameters.Add(gst);

                SqlParameter fs = new SqlParameter();
                fs.ParameterName = "@FleetSize";
                fs.SqlDbType     = SqlDbType.VarChar;
                fs.Value         = n.FleetSize;
                cmd.Parameters.Add(fs);

                SqlParameter sts = new SqlParameter();
                sts.ParameterName = "@StaffSize";
                sts.SqlDbType     = SqlDbType.VarChar;
                sts.Value         = n.StaffSize;
                cmd.Parameters.Add(sts);

                SqlParameter PAdd = new SqlParameter();
                PAdd.ParameterName = "@AlternateAddress";
                PAdd.SqlDbType     = SqlDbType.VarChar;
                PAdd.Value         = n.AlternateAddress;
                cmd.Parameters.Add(PAdd);


                //SqlParameter TAdd = new SqlParameter();
                //TAdd.ParameterName = "@TemporaryAddress";
                //TAdd.SqlDbType = SqlDbType.VarChar;
                //TAdd.Value = n.TemporaryAddress;
                //cmd.Parameters.Add(TAdd);

                SqlParameter logo = new SqlParameter();
                logo.ParameterName = "@Logo";
                logo.SqlDbType     = SqlDbType.VarChar;
                // ImageConverter imgCon = new ImageConverter();
                // logo.Value = (byte[])imgCon.ConvertTo(n.Logo, typeof(byte[]));
                logo.Value = n.Logo;
                cmd.Parameters.Add(logo);

                SqlParameter insupdflag = new SqlParameter("@insupdflag", SqlDbType.VarChar, 1);
                insupdflag.Value = n.insupdflag;
                cmd.Parameters.Add(insupdflag);

                cmd.ExecuteScalar();
                conn.Close();
                traceWriter.Trace(Request, "0", TraceLevel.Info, "{0}", "SaveCompanyGroups Credentials completed.");
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                string str = ex.Message;
                traceWriter.Trace(Request, "1", TraceLevel.Info, "{0}", "Error in SaveCompanyGroups:" + ex.Message);
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }
            // int found = 0;
            //  return Tbl;
        }