public HttpResponseMessage Post(DateTime date, [FromBody] DiaryEntryModel model) { try { string username = _identityService.CurrentUser; DiaryEntry diaryEntry = TheModelFactory.Parse(model); if (diaryEntry == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read diary entry in body")); } Diary diary = TheRepository.GetDiary(username, date); if (diary == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Diary not found")); } if (diary.Entries.Any(entry => entry.Measure.Id == diaryEntry.Measure.Id)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Duplicate measure not allowed")); } diary.Entries.Add(diaryEntry); if (TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(diaryEntry))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save to the database")); } } catch (Exception exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception)); } }
//PUT api/License/26 public HttpResponseMessage PUT(int id, [FromBody] License license) { try { var targetLicense = _theLicenseRepo.GetById(id); if (targetLicense != null && targetLicense.Id == id) { targetLicense.Name = license.Name; targetLicense.Description = license.Description; targetLicense.TitleOfHardware = license.TitleOfHardware; targetLicense.LicenseType = license.LicenseType; targetLicense.Duration = license.Duration; targetLicense.DateCreated = license.DateCreated; targetLicense.DateUpdated = license.DateUpdated; targetLicense.Status = license.Status; targetLicense.ProdFamilyId = license.ProdFamilyId; targetLicense.SubscriptionId = license.SubscriptionId; targetLicense.VersionId = license.VersionId; targetLicense.ApplicationId = license.ApplicationId; targetLicense.ProductTypeId = license.ProductTypeId; _theLicenseRepo.Update(license); var licenseModel = TheModelFactory.Create(license); licenseModel.Id = id; return(Request.CreateResponse(HttpStatusCode.OK, licenseModel)); } else { return(Request.CreateResponse(HttpStatusCode.NotModified, "Not found the license.")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] TokenRequestModel model) { try { var user = TheRepository.GetApiUsers().Where(u => u.AppId == model.ApiKey).FirstOrDefault(); if (user != null) { var secret = user.Secret; var key = Convert.FromBase64String(secret); var provider = new System.Security.Cryptography.HMACSHA256(key); var hash = provider.ComputeHash(Encoding.UTF8.GetBytes(user.AppId)); var signature = Convert.ToBase64String(hash); if (signature == model.Signature) { var rawTokenInfo = String.Concat(user.AppId + DateTime.UtcNow.ToString("d")); var rawTokenByte = Encoding.UTF8.GetBytes(rawTokenInfo); var token = provider.ComputeHash(rawTokenByte); var authToken = new AuthToken() { Token = Convert.ToBase64String(token), Expiration = DateTime.UtcNow.AddDays(7), ApiUser = user }; if (TheRepository.Insert(authToken) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(authToken))); } } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
public async Task <IActionResult> Create([FromBody] FlightViewModel flight) { try { var theGate = await FlightService.GetFlightsByGateIdAsync(flight.GateId); var theFlight = TheModelFactory.Create(flight); var flightId = FlightService.AddFlightToGate(theFlight, theGate); if (flightId == 0) { return(StatusCode(500, "Couldn't create flight.")); } var created = FlightService.GetFlightById(flightId); return(CreatedAtRoute("", created)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName, Level = 3, JoinDate = DateTime.Now.Date, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } string code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); string callbackUrl = ConfigurationManager.AppSettings["emailConfirmationPath"] + "?userId=" + user.Id + "&code=" + HttpContext.Current.Server.UrlEncode(code); await this.AppUserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createUser = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName, Level = 3, JoinDate = DateTime.Now.Date, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } string code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code })); await this.AppUserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); var adminUser = createUser.FindByName(user.UserName); createUser.AddToRoles(adminUser.Id, new string[] { "User" }); return(Created(locationHeader, TheModelFactory.Create(user))); }
public async Task <IHttpActionResult> Create(CreateRoleBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var role = new IdentityRole { Name = model.Name }; var result = await this.AppRoleManager.CreateAsync(role); if (!result.Succeeded) { return(GetErrorResult(result)); } Uri locationHeader = new Uri(Url.Link("GetRoleById", new { id = role.Id })); return(Created(locationHeader, TheModelFactory.Create(role))); }
// Create public HttpResponseMessage Post(DateTime diaryId, [FromBody] DiaryEntryModel model) { //return null; try { var entity = TheModelFactory.Parse(model); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read diary entry in body")); } var diary = TheCountingKsRepository.GetDiary(_identityService.CurrentUser, diaryId); if (diary == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } // Make sure it's not duplicate if (diary.Entries.Any(e => e.Measure.Id == entity.Measure.Id)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Duplicate Measure not allowed.")); } // Save the new Entry diary.Entries.Add(entity); if (TheCountingKsRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save to the database.")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public async Task <IHttpActionResult> RegisterUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser { UserName = createUserModel.Username, Email = createUserModel.Email, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName, Level = 3, JoinDate = DateTime.Now.Date, }; IdentityResult addResult = await AppUserManager.CreateAsync(user); if (!addResult.Succeeded) { return(GetErrorResult(addResult)); } // Send mail after creation an account //la création d'un code unique (token) qui est valide pour les 6 prochaines heures //et lié à cet ID utilisateur, cela se produit uniquement lorsque vous appelez la méthode "GenerateEmailConfirmationTokenAsync", string token = await AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); //code = System.Web.HttpUtility.UrlEncode (code); code = System.Web.HttpUtility.UrlDecode (code) Uri callUrl = new Uri(Url.Link("ConfirmEmailRoute", new { id = user.Id, token = System.Web.HttpUtility.UrlEncode(token) })); await AppUserManager.SendEmailAsync(user.Id, "Activate your Account", "Please confirm your account by clicking href=\"" + callUrl + "\">here</a>"); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, EmailConfirmed = true, ProfileInfo = new UserProfile { FullName = createUserModel.FullName, JoinDate = DateTime.UtcNow, Description = createUserModel.Description, } }; var result = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!result.Succeeded) { return(GetErrorResult(result)); } var assignRole = this.AppRoleManager.FindByName("User"); if (assignRole != null) { await this.AppUserManager.AddToRoleAsync(user.Id, assignRole.Name); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!createUserModel.Email.Contains("gmail.com")) { //return Ok();//error silently. do notreveal.. //instead return a guid..make the user feel he is correct and let him wait forever :) return(Json <string>(Guid.NewGuid().ToString())); } var user = new ApplicationUser() { UserName = createUserModel.Email.Substring(0, createUserModel.Email.IndexOf('@')), //UserName = Guid.NewGuid().ToString().Replace('-' , 'h'),//createUserModel.Username, Email = createUserModel.Email, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, user.UserName); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } string code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code })); await this.AppUserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
public object Get(bool includeMeasures = true, int page = 0) { IQueryable <Food> query; if (includeMeasures) { query = TheRepo.GetAllFoodsWithMeasures(); } else { query = TheRepo.GetAllFoods(); } var baseQuery = query. OrderBy(f => f.Description); var totalCount = baseQuery.Count(); var totalPages = Math.Ceiling((double)totalCount / PAGE_SIZE); var url = new UrlHelper(Request); var prevUrl = page > 0?url.Link("Food", new { page = page - 1 }):""; var nextUrl = page < totalPages - 1?url.Link("Food", new { page = page + 1 }):""; var results = baseQuery .Skip(PAGE_SIZE * page) .Take(PAGE_SIZE) .ToList() .Select(f => TheModelFactory.Create(f)); return(new { TotalCount = totalCount, TotalPages = totalPages, PrevPageUrl = prevUrl, NextPageUrl = nextUrl, Results = results }); }
public async Task <IHttpActionResult> Get(int page = 0, int page_Size = PAGE_SIZE) { var certifications = TheRepository.GetAllCertifications(); // we can do some calculations or some work here if we need to. await certifications; var orderedCertifications = certifications.Result.OrderBy(c => c.Name); var totalCount = orderedCertifications.Count(); var totalPages = Math.Ceiling((double)totalCount / page_Size); var helper = new UrlHelper(Request); var certificatePageModel = new CertificatePageModel(); if (page > 0) { certificatePageModel.prevPage = helper.Link("Certificates", new { page = page - 1 }); } else { certificatePageModel.prevPage = ""; } if (page < totalPages - 1) { certificatePageModel.nextPage = helper.Link("Certificates", new { page = page + 1 }); } else { certificatePageModel.nextPage = ""; } certificatePageModel.CertificateUrIModelList = orderedCertifications.Skip(page_Size * page) .Take(page_Size) .ToList().Select(oc => TheModelFactory.Create(oc)).ToList(); return(Ok(certificatePageModel)); }
public async Task <IHttpActionResult> CreateUser(UserModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new User() { UserName = createUserModel.Username }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } Log.Debug($"{user.UserName} Registered to the system."); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
// GET: api/Slideshows public HttpResponseMessage Get() { IEnumerable <SlideshowModel> slideshows = TheRepository.GetAllSlideshows() .ToList() .Select(sh => TheModelFactory.Create(sh)) .ToList(); if (slideshows == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } foreach (SlideshowModel sh in slideshows) { IEnumerable <SlideModel> slides = TheRepository.GetSlideshowSlides(sh.Id) .ToList() .Select(s => TheModelFactory.Create(s)) .ToList(); sh.Slides = slides; } return(Request.CreateResponse(HttpStatusCode.OK, slideshows)); }
public async Task <IHttpActionResult> Register(User userModel) { if (userModel.ID == null) { userModel.ID = Guid.NewGuid().ToString(); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityResult result = await _repo.RegisterUser(userModel); if (!result.Succeeded) { return(GetErrorResult(result)); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = userModel.ID })); return(Created(locationHeader, TheModelFactory.Create(userModel, true))); }
public HttpResponseMessage Post([FromBody] CourseModel courseModel) { try { var entity = TheModelFactory.Parse(courseModel); if (entity == null) { Request.CreateResponse(HttpStatusCode.BadRequest, "Could not read subject/tutor from body"); } if (TheRepository.Insert(entity) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save to the database.")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public IHttpActionResult Get(int page = 0, int pageSize = 10) { IQueryable <Course> query; //kreiranje paging objekta //result query = TheRepository.GetAllCourses().OrderBy(c => c.CourseSubject.Id); //broj stranica i ukupni broj var totalCount = query.Count(); var totalPages = (int)Math.Ceiling((double)totalCount / pageSize); //prev i next page var urlHelper = new UrlHelper(Request); var prevPage = page > 0 ? urlHelper.Link("Courses", new { page = page - 1 }) : ""; var nextPage = page < totalPages - 1 ? urlHelper.Link("Courses", new { page = page + 1 }) : ""; var results = query .Skip(page * pageSize) .Take(pageSize) .ToList() .Select(s => TheModelFactory.Create(s)); return(Ok(new { TotalCount = totalCount, TotalPages = totalPages, PrevPageLink = prevPage, NextPageLink = nextPage, Results = results })); }
public HttpResponseMessage Post(DateTime diaryid, [FromBody] DiaryEntryModel model) { try { var entity = TheModelFactory.Parse(model); if (entity == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "cannot found entry"); } var diary = TheRepository.GetDiary(_identityService.CurrentUser, diaryid); if (diary == null) { Request.CreateResponse(HttpStatusCode.NotFound); } //check duplicate if (diary.Entries.Any(e => e.Measure.Id == entity.Measure.Id)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "duplicate")); } //save new entry diary.Entries.Add(entity); if (TheRepository.SaveAll()) { LogActivity.LogSend("post", Request); return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(entity))); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "not added")); } } catch (Exception exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception)); } }
public HttpResponseMessage Post(DateTime diaryid, [FromBody] DiaryEntryModel model) { try { var entity = TheModelFactory.Parse(model); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read diary entry in body")); } var diary = TheRepository.GetDiary(_identityService.CurrentUser, diaryid); if (diary == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } //make sure it is not duplicate if (diary.Entries.Any(e => e.Measure.Id == entity.Measure.Id)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Duplicate entries not allowed")); } //save the new entry diary.Entries.Add(entity); if (TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save the changes")); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } return(null); }
public HttpResponseMessage Put(int id, [FromBody] CourseModel courseModel) { try { var updatedCourse = TheModelFactory.Parse(courseModel); if (updatedCourse == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read subject/tutor from body"); } var originalCourse = TheRepository.GetCourse(id, false); if (originalCourse == null || originalCourse.Id != id) { return(Request.CreateResponse(HttpStatusCode.NotModified, "Course is not found")); } else { updatedCourse.Id = id; } if (TheRepository.Update(originalCourse, updatedCourse) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(updatedCourse))); } else { return(Request.CreateResponse(HttpStatusCode.NotModified)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] DiaryModel model) { try { if (TheRepository.GetDiaries(_identityService.CurrentUser).Count(d => d.CurrentDate == model.CurrentDate.Date) > 0) { return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "A diary already exists for that date")); } var entity = TheModelFactory.Parse(model); entity.UserName = _identityService.CurrentUser; if (TheRepository.Insert(entity) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } } catch { // TODO Add Logging } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
public async Task <IHttpActionResult> CreateUser(UserModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = createUserModel.UserName, Email = createUserModel.Email, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName, Birthdate = createUserModel.Birthdate, Level = 3, JoinDate = DateTime.Now.Date, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } #region send confirmation email for the user string code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code })); await this.AppUserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); #endregion Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
public IActionResult GetFilteredTerm(string searchTerm) { var queryParams = this.HttpContext.Request.Query.ToList(); if (queryParams.Any()) { IQueryable <Customer> searchResponse = _customerSevice.DataRepository.GetAll(); var key = this.HttpContext.Request.Query.Keys.ToList().FirstOrDefault(); if (key == "searchTerm") { var param = queryParams.FirstOrDefault().Value.ToString(); var response = searchResponse.SearchByMultiple(searchTerm); return(Ok(response.Select(x => TheModelFactory.Create(x)))); } else { return(BadRequest("No valid search criteria have been provided.")); } } else { return(BadRequest("No valid search criteria have been provided.")); } }
public IHttpActionResult Post([FromBody] CourseModel courseModel) { try { var entity = TheModelFactory.Parse(courseModel); if (entity == null) { return(BadRequest("Could not read subject/tutor from body")); } if (TheRepository.Insert(entity) && TheRepository.SaveAll()) { var newCourseModel = TheModelFactory.Create(entity); return(Created <CourseModel>(new Uri(newCourseModel.Url), newCourseModel)); } else { return(BadRequest("Could not save to database")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, PrimerNombre = createUserModel.PrimerNombre, PrimerApellido = createUserModel.PrimerApellido, SegundoNombre = createUserModel.SegundoNombre, SegundoApellido = createUserModel.SegundoApellido, LicenseExpiration = DateTime.Now.Date }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } string code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code })); await this.AppUserManager.SendEmailAsync(user.Id, "Confirmar Cuenta", "Por Favor Confirme Su Cuenta Haciendo Click En El Siguente Enlace. <a href=\"" + callbackUrl + "\"></a>"); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
public async Task <IHttpActionResult> CreateUser(IdentityUser user) { var addUser = await AppUserManager.CreateAsync(user); if (!addUser.Succeeded) { Logger.ServiceLog.Warn("Ошибка регистрации пользователя"); return(GetErrorResult(addUser)); } var code = await AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); code = HttpUtility.UrlEncode(code); var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code })); await AppUserManager.SendEmailAsync(user.Id, "Подтверждение аккаунта в DropBoxDuplicate", "<strong>Подтвердите ваш аккаунт</strong>: <a href=\"" + callbackUrl + "\">Ссылка</a>"); var locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); Logger.ServiceLog.Info($"Пользователь {user.Id} успешно зарегистрирован."); return(Created(locationHeader, TheModelFactory.Create(user))); }
protected object CreateResponse(IQueryable <Infraccion> query, int page, int pageSize, string controller) { page = page - 1; var totalCount = query.Count(); var totalPages = (int)System.Math.Ceiling((double)totalCount / pageSize); var urlHelper = new UrlHelper(Request); var prevLink = page > 0 ? urlHelper.Link(controller, new { page = page - 1, pageSize = pageSize }) : ""; var nextLink = page < totalPages - 1 ? urlHelper.Link(controller, new { page = page + 1, pageSize = pageSize }) : ""; var results = query.Skip(pageSize * page) .Take(pageSize) .ToList() .Select(s => TheModelFactory.Create(s)); return(new { TotalCount = totalCount, TotalPages = totalPages, PrevPageLink = prevLink, NextPageLink = nextLink, Results = results }); }
public IHttpActionResult Get(int foodid) { return(Versioned(TheModelFactory.Create(TheRepo.GetFood(foodid)), "V1")); // return new VersionedActionResult<FoodModel>(this.Request, "V2", TheModelFactory.Create(TheRepo.GetFood(foodid))); }