本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}