當前位置: 首頁>>代碼示例>>C#>>正文


C# Http.User類代碼示例

本文整理匯總了C#中System.Web.Http.User的典型用法代碼示例。如果您正苦於以下問題:C# User類的具體用法?C# User怎麽用?C# User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


User類屬於System.Web.Http命名空間,在下文中一共展示了User類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Post

        // POST odata/User
        public virtual async Task<IHttpActionResult> Post(User user)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                await MainUnitOfWork.InsertAsync(user);
            }
            catch (DbUpdateException)
            {
                if (MainUnitOfWork.Exists(user.Id))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return Created(user);
        }
開發者ID:gitter-badger,項目名稱:WealthEconomy,代碼行數:26,代碼來源:UsersController.cs

示例2: GetUserByUserName

        public object GetUserByUserName(string userName)
        {
            //logger.Debug("Start");
            User user = new User();

            try
            {
                if (String.IsNullOrEmpty(userName))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    user = _ldapService.GetUserByUserName(userName);
                }

            }
            catch (Exception e)
            {

                logger.ErrorException("Exception", e);
            }

            return user;
        }
開發者ID:patrickwensel,項目名稱:WS,代碼行數:25,代碼來源:LDAPController.cs

示例3: BuildShip

        /// <summary>
        /// Builds new Ship from preset, user, and cellTypes
        /// </summary>
        /// <param name="owner">User, who owns the Ship</param>
        /// <param name="preset">Ship preset</param>
        /// <param name="cellTypes">cellTypes[i] - type of room with id = i</param>
        /// <returns>Built Ship</returns>
        public Ship BuildShip(User owner, ShipPreset preset, IEnumerable<int> cellTypes)
        {
            Ship ship = new Ship(owner, preset.RoomIds.GetLength(1), preset.RoomIds.GetLength(0));
            ship.preset = preset;

            currentWeaponId = 0;
            assignedWeaponIds = new Dictionary<int, int>();

            for (int i = 0; i < ship.cells.Length; i++)
            {
                for (int j = 0; j < ship.cells[i].Length; j++)
                {
                    int roomId = preset.RoomIds[i, j];
                    ship.cells[i][j] = buildCell(ship, cellTypes.ToList()[roomId], roomId);
                    if (currentWeaponId >= preset.weapons.Length) currentWeaponId = 0;
                }
            }

            assignesStatuses = new Dictionary<int, CellStatus>();
            InitCellStatuses(ship, preset);

            if (preset.afterShipBuilt != null)
                preset.afterShipBuilt.Invoke(ship);

            return ship;
        }
開發者ID:GLAVAK,項目名稱:AIGame,代碼行數:33,代碼來源:ShipBuilder.cs

示例4: Put

        // PUT odata/User(5)
        public virtual async Task<IHttpActionResult> Put([FromODataUri] int key, User user)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (key != user.Id)
            {
                return BadRequest();
            }

            try
            {
                await MainUnitOfWork.UpdateAsync(user);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MainUnitOfWork.Exists(key))
                {
                    return NotFound();
                }
                else
                {
                    return Conflict();
                }
            }

            return Ok(user);
        }
開發者ID:gitter-badger,項目名稱:WealthEconomy,代碼行數:31,代碼來源:UsersController.cs

示例5: PutUser

        public IHttpActionResult PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != user.UserID)
            {
                return BadRequest();
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
開發者ID:jackngare,項目名稱:LEproj,代碼行數:32,代碼來源:UsersController.cs

示例6: GetEvent

        public IHttpActionResult GetEvent(int id)
        {
            Event @event = db.Events.Find(id);
            if (@event == null)
            {
                return NotFound();
            }
            List<User> custUserList = new List<User>();
            foreach (User myUser in @event.Users)
            {
                User custUser = new User();
                custUser.address = myUser.address;
                custUser.credit = myUser.credit;
                custUser.dob = myUser.dob;
                custUser.email = myUser.email;
                custUser.emgcontact = myUser.emgcontact;
                custUser.emgrelationship = myUser.emgrelationship;
                custUser.Events = new List<Event>();
                custUser.fbtoken = myUser.fbtoken;
                custUser.gender = myUser.gender;
                custUser.geocode = myUser.geocode;
                custUser.id = myUser.id;
                custUser.ImgUrl = myUser.ImgUrl;
                custUser.name = myUser.name;
                custUser.phone = myUser.phone;
                custUser.ubertoken = myUser.ubertoken;
                custUserList.Add(custUser);

            }
            @event.Users = custUserList;
            return Ok(@event);
        }
開發者ID:seeyouu87,項目名稱:HangOver,代碼行數:32,代碼來源:EventsController.cs

示例7: CreateUser

        public async Task<IHttpActionResult> CreateUser(UserCreationDto dto)
        {
            if (UserNameExists(dto.UserName))
            {
                return BadRequest("已存在此登錄名");
            }
            //create user
            var user = new User
            {
                UserName = dto.UserName,
                DisplayName = dto.DisplayName,
                Class = dto.ClassNumber,
                Grade = dto.Grade,
                Roles = new HashSet<UserRole>()
            };

            var result = await _userManager.CreateAsync(user, dto.Password);

            if (!result.Succeeded)
            {
                return BadRequest(string.Join(" ", result.Errors));
            }

            var userId = (await _userManager.FindByNameAsync(user.UserName)).Id;

            //add to role
            dto.Roles.ToList().ForEach(rs => { _userManager.AddToRole(userId, rs); });
            return StatusCode(HttpStatusCode.Accepted);
        }
開發者ID:Zjazure,項目名稱:FailureTroubleshooting,代碼行數:29,代碼來源:IdentityController.cs

示例8: FindUsers

        public IHttpActionResult FindUsers(string q = null, bool rq = false)
        {
            IEnumerable<User> Users = null;

            if (q == null)
            {
                Users = Lookup.Data.AllUsers();
            }
            else
            {
                Users = Lookup.Data.FindUsers(q);
            }

            if (rq)
            {
                var User = new User();
                User.Name = q;
                User.Title = "Click here if the user is not listed below.";
                User.Office = string.Empty;
                User.PhotoUrl = Properties.Settings.Default.NoPhotoImageUrl;
                Users = Users.Concat(new User[] { User });
            }

            return Ok(Users);
        }
開發者ID:GuildfordBC,項目名稱:activedirectory-api,代碼行數:25,代碼來源:UsersController.cs

示例9: PutUser

        // PUT api/Users/5
        public HttpResponseMessage PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != user.Id)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
開發者ID:nathanfl,項目名稱:AAHIPro,代碼行數:26,代碼來源:UsersController.cs

示例10: PostUser

        // POST api/User
        public HttpResponseMessage PostUser(User user)
        {
            if (ModelState.IsValid)
            {
                if (!db.Users.Any())
                {
                    user.UserID = 0;
                }
                else
                {
                    user.UserID = db.Users.Max(record => record.UserID) + 1;
                }

                db.Users.Add(user);
                db.SaveChanges();
                db.Configuration.ProxyCreationEnabled = false;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, user);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = user.UserID }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
開發者ID:nghia2080,項目名稱:CProject,代碼行數:26,代碼來源:UserController.cs

示例11: GetTasksListByDate

        public static TaskListModel GetTasksListByDate(DateTime date, User currentUser)
        {
            BYEntities db = new BYEntities();
            List<Task> tempUncTasks = db.Tasks.Where(x => db.Calendars.Any(
                    y => EntityFunctions.TruncateTime(y.Date) == date
                    && x.Id == y.TaskId
                    && y.UserId == currentUser.Id
                    && y.TaskCompleted == false)).ToList();

            List<TasksModel> uncompletedTasks = new List<TasksModel>();
            foreach (Task tsk in tempUncTasks)
            {
                uncompletedTasks.Add(new TasksModel(tsk));
            }

            List<Task> tempCompTasks = db.Tasks.Where(x => db.Calendars.Any(
                y => EntityFunctions.TruncateTime(y.Date) == date
                && x.Id == y.TaskId
                && y.UserId == currentUser.Id
                && y.TaskCompleted == true)).ToList();

            List<TasksModel> completedTasks = new List<TasksModel>();
            foreach (Task tsk in tempCompTasks)
            {
                completedTasks.Add(new TasksModel(tsk));
            }
            return new TaskListModel(completedTasks, uncompletedTasks);
        }
開發者ID:keydown,項目名稱:ChicksBook,代碼行數:28,代碼來源:TasksController.cs

示例12: Put

        // PUT odata/User(5)
        public async Task<IHttpActionResult> Put([FromODataUri] string key, User user)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (key != user.Id)
            {
                return BadRequest();
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(user);
        }
開發者ID:R4CLucky14,項目名稱:UTCCatholic,代碼行數:33,代碼來源:UserController.cs

示例13: RegisterUser

        public async Task<HttpResponseMessage> RegisterUser(RegisterBindingModel userData)
        {
            if (!ModelState.IsValid)
            {
                return await this.BadRequest(this.ModelState).ExecuteAsync(new CancellationToken());
            }

            var user = new User
            {
                UserName = userData.Username,
                Email = userData.Email,
                Name = userData.Name
            };

            var identityResult = await this.UserManager.CreateAsync(user, userData.Password);

            if (!identityResult.Succeeded)
            {
                return await this.GetErrorResult(identityResult).ExecuteAsync(new CancellationToken());
            }

            var loginResult = this.LoginUser(new LoginBindingModel()
            {
                Username = userData.Username,
                Password = userData.Password
            });

            return await loginResult;
        }
開發者ID:antoniapavlova,項目名稱:TechShop,代碼行數:29,代碼來源:UserController.cs

示例14: Post

 public int Post(User user)
 {
     if (user == null)
         return 0;
     if (user.Password == null)
         return 0;
     return service.SignInUser(user.Email, user.Password.Password);
 }
開發者ID:foster-hub,項目名稱:box-cms,代碼行數:8,代碼來源:Core_SigninController.cs

示例15: UpdateUser

 public void UpdateUser(User userUpdated)
 {
     //TODO - Deal with null
     var user = GetUser(userUpdated.Id);
     user.Username = userUpdated.Username;
     user.FirstName = userUpdated.FirstName;
     user.LastName = userUpdated.LastName;
     _ctx.SaveChanges();
 }
開發者ID:ryanmcintire,項目名稱:SimpleContactAPI,代碼行數:9,代碼來源:UserRepo.cs


注:本文中的System.Web.Http.User類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。