public override GetCircleLikesResponseBody ExecuteCore() { GetCircleLikesResponseBody res = new GetCircleLikesResponseBody(); using (HWLEntities db = new HWLEntities()) { var likes = db.t_circle_like.Where(c => c.circle_id == this.request.CircleId && c.is_delete == false) .Select(c => new { LikeId = c.id, CircleId = c.circle_id, LikeUserId = c.like_user_id, LikeTime = c.like_time }).OrderBy(c => c.LikeId).ToList(); if (likes == null || likes.Count <= 0) { return(res); } res.CircleLikeInfos = new List <CircleLikeInfo>(); var userIds = likes.Select(c => c.LikeUserId).ToList(); var userList = db.t_user.Where(i => userIds.Contains(i.id)).Select(i => new { i.id, i.name, i.symbol, i.head_image }).ToList(); likes.ForEach(f => { CircleLikeInfo model = new CircleLikeInfo() { LikeId = f.LikeId, LikeUserId = f.LikeUserId, CircleId = f.CircleId, LikeTime = GenericUtility.FormatDate(f.LikeTime), }; if (userList != null && userList.Count > 0) { var likeUser = userList.Where(u => u.id == f.LikeUserId).FirstOrDefault(); if (likeUser != null) { model.LikeUserName = UserUtility.GetShowName(likeUser.name, likeUser.symbol); model.LikeUserImage = likeUser.head_image; } } res.CircleLikeInfos.Add(model); }); } return(res); }
public override GetNearLikesResponseBody ExecuteCore() { GetNearLikesResponseBody res = new GetNearLikesResponseBody(); var likes = db.t_near_circle_like.Where(c => c.near_circle_id == this.request.NearCircleId && c.is_delete == false) .Select(c => new { LikeId = c.id, NearCircleId = c.near_circle_id, LikeUserId = c.like_user_id, LikeTime = c.like_time }).OrderBy(c => c.LikeId).ToList(); if (likes == null || likes.Count <= 0) { return(res); } res.NearCircleLikeInfos = new List <NearCircleLikeInfo>(); var userIds = likes.Select(c => c.LikeUserId).ToList(); var userList = db.t_user.Where(i => userIds.Contains(i.id)).Select(i => new { i.id, i.name, i.head_image }).ToList(); var friendList = db.t_user_friend.Where(f => f.user_id == this.request.UserId && userIds.Contains(f.friend_user_id)).Select(f => new { f.friend_user_id, f.friend_user_remark }).ToList(); likes.ForEach(f => { NearCircleLikeInfo model = new NearCircleLikeInfo() { LikeId = f.LikeId, LikeUserId = f.LikeUserId, NearCircleId = f.NearCircleId, LikeTime = GenericUtility.FormatDate(f.LikeTime), }; if (userList != null && userList.Count > 0) { var likeUser = userList.Where(u => u.id == f.LikeUserId).FirstOrDefault(); if (likeUser != null) { string friendRemark = friendList != null ? friendList.Where(r => r.friend_user_id == f.LikeUserId).Select(r => r.friend_user_remark).FirstOrDefault() : null; model.LikeUserName = UserUtility.GetShowName(friendRemark, likeUser.name); model.LikeUserImage = likeUser.head_image; } } res.NearCircleLikeInfos.Add(model); }); return(res); }
private void BindInfo(NearCircleInfo info) { info.Images = db.t_near_circle_image.Where(i => i.near_circle_id == info.NearCircleId).Select(i => new ImageInfo() { Url = i.image_url, Height = i.height, Width = i.width }).ToList(); var user = db.t_user.Where(u => u.id == info.PublishUserId).FirstOrDefault(); string friendRemark = db.t_user_friend.Where(f => f.user_id == this.request.UserId && f.friend_user_id == info.PublishUserId).Select(f => f.friend_user_remark).FirstOrDefault(); info.PublishUserName = UserUtility.GetShowName(friendRemark, user.name); info.PublishUserImage = user.head_image; info.IsLiked = db.t_near_circle_like.Where(l => l.near_circle_id == info.NearCircleId && l.like_user_id == this.request.UserId && l.is_delete == false).Select(l => l.id).FirstOrDefault() > 0 ? true : false; }
public async Task Load(string login) { if (!GlobalHelper.IsInternet()) { Messenger.Default.Send(new GlobalHelper.NoInternetMessageType()); //Sending NoInternet message to all viewModels } else { Messenger.Default.Send(new GlobalHelper.HasInternetMessageType()); //Sending Internet available message to all viewModels if (!string.IsNullOrWhiteSpace(login)) { isLoading = true; Developer = await UserUtility.getUserInfo(login); if (Developer != null) { await TryLoadUserAvatarImagesAsync(Developer); } isLoading = false; if (Developer.Type == AccountType.Organization || Developer.Login == GlobalHelper.UserLogin) { CanFollow = false; } else { CanFollow = true; FollowProgress = true; if (await UserUtility.checkFollow(Developer.Login)) { IsFollowing = true; } FollowProgress = false; FollowersLoading = true; Followers = await UserDataService.getAllFollowers(Developer.Login); FollowersLoading = false; FollowingLoading = true; Following = await UserDataService.getAllFollowing(Developer.Login); FollowingLoading = false; } } } }
//[ValidateAntiForgeryToken] public async Task <ActionResult> CreateRecurringGoal([Bind(Include = "AccountNum,GoalPeriod,LimitValue,StartDate,Description")] Goal userGoal) { var uid = User.Identity.GetUserId(); userGoal.GoalType = GoalTypeEnum.Recurring; // Validate that Goal is recurring /*Placed here to comply w/ EndDate greater than StartDate*/ switch (userGoal.GoalPeriod) { case GoalPeriodEnum.Weekly: userGoal.EndDate = userGoal.StartDate.AddDays(7); break; case GoalPeriodEnum.Monthly: userGoal.EndDate = userGoal.StartDate.AddMonths(1); break; case GoalPeriodEnum.Yearly: userGoal.EndDate = userGoal.StartDate.AddYears(1); break; default: ViewData["accountNums"] = await UserUtility.GetUserAccountsList(db, uid); return(View(userGoal)); } //Validate rest of model if (ModelState.IsValid) { //Assign other starting values userGoal.UserID = uid; userGoal.StartValue = 0; //userGoal.GoalType = GoalTypeEnum.Recurring; userGoal.Completed = false; //Save changes and redirect db.Goals.Add(userGoal); await db.SaveChangesAsync(); return(Redirect("AccountGoals/" + userGoal.AccountNum)); } ViewData["accountNums"] = await UserUtility.GetUserAccountsList(db, uid); return(View(userGoal)); }
/// <summary> /// Updates the two avatar images for the current user /// </summary> /// <param name="overrideUser">An optional, explicit user to load instead of the default one</param> /// <param name="blur">The amount of blur to use</param> protected async Task TryLoadUserAvatarImagesAsync([CanBeNull] User overrideUser = null, int blur = 128) { // Pick the target user to load User candidate = overrideUser ?? User; if (candidate == null) { return; } // Update the images CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); Tuple <ImageSource, ImageSource> images = await UserUtility.GetDeveloperAvatarOptionsAsync(candidate, blur, cts.Token); UserAvatar = images?.Item1; UserBlurredAvatar = images?.Item2; }
public async Task Load(object user) { if (GlobalHelper.IsInternet()) { isLoading = true; if (user is string login) { if (!string.IsNullOrWhiteSpace(login)) { Developer = await UserUtility.GetUserInfo(login); } } else { Developer = user as User; if (Developer != null && Developer.Name == null) { Developer = await UserUtility.GetUserInfo(Developer.Login); } } if (Developer != null) { if (Developer.Type == AccountType.Organization || Developer.Login == GlobalHelper.UserLogin) { CanFollow = false; } else { CanFollow = true; FollowProgress = true; if (await UserUtility.CheckFollow(Developer.Login)) { IsFollowing = true; } FollowProgress = false; } IsEventsLoading = true; Events = await ActivityService.GetUserPerformedActivity(Developer.Login); IsEventsLoading = false; } isLoading = false; } }
public HttpResponseMessage Apply(int competitionId) { var token = Request.Headers.Authorization.Parameter; string userEmail = UserUtility.GetEmailByToken(token); User user = _userRepository.GetByEmail(userEmail); CustomResponse response; //checks whether user is the team leader if (user.team != null && user.team.leaderId == user.id) { Competition comp = _repository.GetById(competitionId); //Null check for competition if (comp == null) { response = ResponseMessageHelper.CreateResponse(HttpStatusCode.NotFound, true, HttpStatusCode.NotFound, ConstantResponse.COMPETITITON_APPLIED_NO_COMP_FOUND); return(Request.CreateResponse <CustomResponse>(HttpStatusCode.NotFound, response)); } //Checks whether competition is active or not else if (comp.endDate < DateTime.Now) { response = ResponseMessageHelper.CreateResponse(HttpStatusCode.BadRequest, true, HttpStatusCode.BadRequest, ConstantResponse.COMPETITION_APPLIED_NOT_ACTIVE); return(Request.CreateResponse <CustomResponse>(HttpStatusCode.BadRequest, response)); } //Checks whether the team has already applied or not bool teamAlreadyApplied = _repository.HasAlreadyApplied(competitionId, user.teamId); if (teamAlreadyApplied) { response = ResponseMessageHelper.CreateResponse(HttpStatusCode.BadRequest, true, HttpStatusCode.BadRequest, ConstantResponse.COMPETITION_APPLIED_ALREADY); return(Request.CreateResponse <CustomResponse>(HttpStatusCode.BadRequest, response)); } //Adds the application to the DB _repository.Apply(comp.id, user.team.id); response = ResponseMessageHelper.CreateResponse(HttpStatusCode.OK, false, HttpStatusCode.OK, ConstantResponse.COMPETITION_APPLIED_SUCCESS); return(Request.CreateResponse <CustomResponse>(HttpStatusCode.OK, response)); } response = ResponseMessageHelper.CreateResponse(HttpStatusCode.BadRequest, true, HttpStatusCode.BadRequest, ConstantResponse.COMPETITION_APPLIED_NOT_TEAMLEADER); return(Request.CreateResponse <CustomResponse>(HttpStatusCode.BadRequest, response)); }
private async Task LoadOrganizations() { var orgs = await UserUtility.GetAllOrganizations(); if (orgs.Count == 0 || orgs == null) { ZeroOrganizations = true; if (Organizations != null) { Organizations.Clear(); } } else { ZeroOrganizations = false; Organizations = orgs; } }
private async Task LoadRepos() { var repos = await UserUtility.GetUserRepositories(); if (repos.Count == 0 || repos == null) { ZeroRepo = true; if (Repositories != null) { Repositories.Clear(); } } else { ZeroRepo = false; RepositoriesNotFiltered = Repositories = repos; } }
private async Task LoadStarRepos() { var starred = await UserUtility.GetStarredRepositories(); if (starred.Count == 0 || starred == null) { ZeroStarRepo = true; if (StarredRepositories != null) { StarredRepositories.Clear(); } } else { ZeroStarRepo = false; StarredRepositoriesNotFiltered = StarredRepositories = starred; } }
// GET: Asks public ActionResult Index() { var role = HogwartsSettingUtility.GetNowDisplayRole(); var asks = db.Asks.Where(x => x.Role == role && x.ParentAskId == -1) .OrderByDescending(x => x.UpdateDateTime) .ToList(); var answer = db.Asks.Where(x => x.Role == role && x.ParentAskId != -1) .OrderBy(x => x.UpdateDateTime) .ToList(); var users = UserUtility.GetUserListInNowDisplayGroup().ToDictionary(u => u.Id); var askViewModels = asks.Select(x => { ApplicationUser user; var existUser = false; var isMyAsk = false; if (users.TryGetValue(x.CreateUserId, out user)) { existUser = true; } if ((existUser && user.UserID == User.Identity.Name) || User.IsInRole("Admin")) { isMyAsk = true; } return(new AskViewModel { Id = x.Id, ParentAskId = x.ParentAskId, Content = x.Content.HtmlToPlainText(50), CreateDateTime = x.CreateDateTime, UpdateDateTime = x.UpdateDateTime, IsClosed = x.IsClosed, Role = x.Role, AnswerCount = answer.Count(y => y.ParentAskId == x.Id), CreateUserId = existUser ? user.UserID : "manager", CreateUserName = existUser ? user.UserName : "******", IsMyAsk = isMyAsk }); }); return(View(askViewModels)); }
public async Task LoadEvents() { PaginationIndex++; if (PaginationIndex > 1) { IsIncrementalLoading = true; var events = await UserUtility.GetUserActivity(PaginationIndex); if (events != null) { if (events.Count > 0) { foreach (var i in events) { Events.Add(i); } } else { //no more feed items left to load PaginationIndex = -1; } } IsIncrementalLoading = false; } else if (PaginationIndex == 1) { Events = await UserUtility.GetUserActivity(PaginationIndex); if (Events != null) { if (Events.Count == 0) { PaginationIndex = 0; ZeroEventCount = true; } else { ZeroEventCount = false; } } } }
public void AddCategoryStatistics_ShouldNotThrow_WhenUserIdIsNotFound(string id) { //Arrange var mockUserRepository = new Mock <IRepository <User> >(); var mockCategoryStatisticsRepository = new Mock <IRepository <CategoryStatistic> >(); var mockUserFactory = new Mock <IUserFactory>(); var mockUnitOfWork = new Mock <IUnitOfWork>(); var utility = new UserUtility(mockUserRepository.Object, mockCategoryStatisticsRepository.Object, mockUserFactory.Object, mockUnitOfWork.Object ); var mockCategoryStatistics = new Mock <IEnumerable <CategoryStatisticHelper> >(); //Act && Assert Assert.DoesNotThrow(() => utility.AddCategoryStatistics(id, mockCategoryStatistics.Object)); }
public async void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e) { Pivot p = sender as Pivot; if (p.SelectedIndex == 0) { IsLoadingOpen = true; OpenIssues = await RepositoryUtility.GetAllIssuesForRepo(Repository.Id, new RepositoryIssueRequest { State = ItemStateFilter.Open }, OpenPaginationIndex = 1); IsLoadingOpen = false; ZeroOpenIssues = OpenIssues.Count == 0 ? true : false; MaxOpenScrollViewerVerticalffset = 0; } else if (p.SelectedIndex == 1) { IsLoadingClosed = true; ClosedIssues = await RepositoryUtility.GetAllIssuesForRepo(Repository.Id, new RepositoryIssueRequest { State = ItemStateFilter.Closed }, ClosedPaginationIndex = 1); IsLoadingClosed = false; ZeroClosedIssues = ClosedIssues.Count == 0 ? true : false; MaxClosedScrollViewerVerticalffset = 0; } else if (p.SelectedIndex == 2) { IsLoadingMine = true; MyIssues = await UserUtility.GetAllIssuesForRepoByUser(Repository.Id); IsLoadingMine = false; ZeroMyIssues = MyIssues.Count == 0 ? true : false; } }
public async Task Load() { if (!GlobalHelper.IsInternet()) { //Sending NoInternet message to all viewModels Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType { Message = "No Internet", Glyph = "\uE704" }); } else { isLoading = true; if (User != null) { if (GlobalHelper.NewFollowActivity) { User = await UserUtility.GetUserInfo(User.Login); GlobalHelper.NewFollowActivity = false; } isLoggedin = true; if (User.Type == AccountType.Organization) { IsOrganization = true; } else { Followers = await UserUtility.GetAllFollowers(User.Login); Following = await UserUtility.GetAllFollowing(User.Login); } } else { isLoggedin = false; } isLoading = false; } }
public async void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e) { Pivot p = sender as Pivot; if (p.SelectedIndex == 0) { IsEventsLoading = true; if (Developer != null) { Events = await ActivityService.GetUserPerformedActivity(Developer.Login); } IsEventsLoading = false; } else if (p.SelectedIndex == 1) { IsReposLoading = true; await LoadRepos(); IsReposLoading = false; } else if (p.SelectedIndex == 2) { IsStarredReposLoading = true; await LoadStarredRepos(); IsStarredReposLoading = false; } else if (p.SelectedIndex == 3) { IsFollowersLoading = true; Followers = await UserUtility.GetAllFollowers(Developer.Login); IsFollowersLoading = false; } else if (p.SelectedIndex == 4) { IsFollowingLoading = true; Following = await UserUtility.GetAllFollowing(Developer.Login); IsFollowingLoading = false; } }
public async Task LoadUser(User user) { if (user != null) { GlobalHelper.UserLogin = user.Login; isLoggedin = true; Messenger.Default.Send <User>(user); User = user; if (user.Email == null) { // If User's email is not visible publicly, the email field will return null // In this case we have to get the email separately this.Email = await UserUtility.GetUserEmail(); } else { Email = user.Email; } } }
/* * Call a service to get a user by userId. It returns UserData type. * This method calls the utility class UserUtility to convert the data to a PersonModel object * and returns the PersonModel object * After use it disposes the UserUtility object */ public UserModel getUserId(int userId) { UserModel userModel = null; UserData user; try { IUserService _userServiceId = createServiceClient(); user = _userServiceId.GetUserById(userId); userModel = UserUtility.ConvertUserDataToUserModelData(user); } catch (ServiceAccessException) { throw new ServiceAccessException(ExceptionMessages.Couldnt_Retrive_User_From_Service); } return(userModel); }
public HttpResponseMessage GetTeamMembers() { var token = Request.Headers.Authorization.Parameter; User user = UserUtility.GetUserByToken(token); Nullable <int> teamId = user.teamId; CustomResponse response; using (M32COMDBSERVER DB = new M32COMDBSERVER()) { if (teamId != null) { IEnumerable <UserDTO> result = _repository.GetTeamMembers(teamId); response = ResponseMessageHelper.CreateResponse(HttpStatusCode.OK, false, result, ConstantResponse.OK); return(Request.CreateResponse <CustomResponse>(HttpStatusCode.OK, response)); } //returns null if the user does not have a team response = ResponseMessageHelper.CreateResponse(HttpStatusCode.OK, false, null, ConstantResponse.TEAM_GET_MEMBERS); return(Request.CreateResponse <CustomResponse>(HttpStatusCode.OK, response)); } }
public async Task <ActionResult> AddTransaction([Bind(Include = "AccountNum,Amount,TransactionType,Description")] CustomerTransaction cusTrans) { var uid = User.Identity.GetUserId(); ViewData["transAccountNum"] = await UserUtility.GetUserAccountsList(db, uid); if (ModelState.IsValid) { cusTrans.TransactionDate = DateTime.Now; // Update Goals await UserUtility.UpdateGoal(uid, cusTrans); db.CustomerTransactions.Add(cusTrans); await db.SaveChangesAsync(); return(RedirectToAction("Index", "CustomerAccount")); } return(View(cusTrans)); }
public JsonResult UpdateMOU(bool chkMOU) { bool errored = false; try { PhysicianRepository physicianRepos = new PhysicianRepository(); physicianRepos.UpdateMOU(User.Identity.Name, (chkMOU ? 1 : 0)); UserUtility.ReloadUser(Session, User.Identity.Name); Domain.User user = Cholestabetes.Mobile.Helper.UserUtility.GetLoggedInUser(Session, User.Identity.Name) as Domain.User; } catch (Exception) { errored = true; } return(Json(new { Result = errored ? 0 : 1 }, JsonRequestBehavior.AllowGet)); }
protected void Page_Load(object sender, EventArgs e) { UserUtility userUtility = new UserUtility(); if (Request.HttpMethod == "POST") { string strRoles = Request.Form["Roles"]; string strUsername = Request.Form["username"]; string strPassword = Request.Form["password"]; string strEmail = Request.Form["email"]; UserModel userModel = new UserModel { Username = strUsername, Password = strPassword, Email = strEmail, Roles = strRoles }; if (!string.IsNullOrEmpty(userModel.Username) || !string.IsNullOrEmpty(userModel.Password) || !string.IsNullOrEmpty(userModel.Email)) { if (userUtility.InsertUser(userModel) == "Success") { toastrUtilities.SessionPush("toast", new KeyValuePair <string, string>("success", $"{strUsername.ToUpper()} Successfully Added.")); } else { toastrUtilities.SessionPush("toast", new KeyValuePair <string, string>("error", $"An Error Occured Please Contact System Administrator.")); } } else { toastrUtilities.SessionPush("toast", new KeyValuePair <string, string>("error", $"Please fill up all Fields!")); } } rolesModels = roleUtilities.GetRoles(); roleGroup = rolesModels.GroupBy(x => x.GroupId).Select(y => y.First()).ToList(); usersBody.InnerHtml = ShowUsers(userUtility.GetUsers()).ToString(); }
// Attempt to log user in, show error message if fail protected void LoginClick(object sender, EventArgs e) { try { // Get list of users from stored procedure List <User> users = UserUtility.GetUsers(); User found = null; // Check each user in list against input foreach (User user in users) { if (user.username == Username.Text) { if (user.password == Password.Text) { found = user; } } } // If user is found set gloabl user and // redirect to sitemap if (found != null) { Session[Global.user] = found; Response.Redirect("Sitemap.aspx"); } // Show error message if user not found else { InvalidLoginError.Visible = true; } } // If exception caught display database error catch (Exception) { DataBaseError.Visible = true; } }
public async Task Load(string login) { if (!GlobalHelper.IsInternet()) { //Sending NoInternet message to all viewModels Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType { Message = "No Internet", Glyph = "\uE704" }); } else { if (!string.IsNullOrWhiteSpace(login)) { isLoading = true; Developer = await UserUtility.GetUserInfo(login); isLoading = false; if (Developer.Type == AccountType.Organization || Developer.Login == GlobalHelper.UserLogin) { CanFollow = false; } else { CanFollow = true; FollowProgress = true; if (await UserUtility.CheckFollow(Developer.Login)) { IsFollowing = true; } FollowProgress = false; IsEventsLoading = true; Events = await ActivityService.GetUserPerformedActivity(Developer.Login); IsEventsLoading = false; } } } }
public void AddCategoryStatistics_ShouldUpdateCategoryStatistic_WhenItExists() { //Arrange var mockUserRepository = new Mock <IRepository <User> >(); var mockCategoryStatisticsRepository = new Mock <IRepository <CategoryStatistic> >(); var mockUserFactory = new Mock <IUserFactory>(); var mockUnitOfWork = new Mock <IUnitOfWork>(); var utility = new UserUtility(mockUserRepository.Object, mockCategoryStatisticsRepository.Object, mockUserFactory.Object, mockUnitOfWork.Object ); var fakeCategoryStatisticsHelper = new List <CategoryStatisticHelper> { new CategoryStatisticHelper(0) }.AsEnumerable(); var fakeUser = new User(); mockUserRepository.Setup(x => x.GetById(It.IsAny <string>())).Returns(fakeUser); var fakeCategoryStatistics = new List <CategoryStatistic> { new CategoryStatistic { UserId = fakeUser.Id, CategoryId = 0 } }.AsQueryable(); mockCategoryStatisticsRepository.Setup(x => x.Entities).Returns(fakeCategoryStatistics); //Act utility.AddCategoryStatistics(It.IsAny <string>(), fakeCategoryStatisticsHelper); //Assert mockCategoryStatisticsRepository.Verify(x => x.Update(It.IsAny <CategoryStatistic>()), Times.Once); }
public static IApplicationBuilder UserIdentity(this IApplicationBuilder builder) { return(builder.Use(async(httpContext, next) => { int userid; DateTime time; string token = httpContext.Request.Cookies["token"] ?? ""; try { if (UserUtility.GetIdByToken(token, out userid, out time)) { UserInfo user = null; IMemoryCache cache = httpContext.RequestServices.GetService(typeof(IMemoryCache)) as IMemoryCache; user = cache.GetUser(userid); if (user == null) { UserInfoRepository repository = httpContext.RequestServices.GetService(typeof(UserInfoRepository)) as UserInfoRepository; if (repository != null) { user = repository.FindFirst(n => n.Id == userid); cache.SetUser(user); } } if (user != null) { httpContext.Items.Add("user", user); } } } catch (Exception ex) { Console.WriteLine(ex.Message + ex.StackTrace); } await next.Invoke(); })); }
public HttpResponseMessage GetBoat() { var token = Request.Headers.Authorization.Parameter; User sender = UserUtility.GetUserByToken(token); CustomResponse response; if (sender.team == null) { response = ResponseMessageHelper.CreateResponse(HttpStatusCode.OK, false, null, ConstantResponse.TEAM_BOAT_GET_NO_TEAM); } else if (sender.team.boat == null) { response = ResponseMessageHelper.CreateResponse(HttpStatusCode.OK, false, null, ConstantResponse.TEAM_BOAT_GET_NO_BOAT); } else { BoatDTO boatDTO = GenericMapper.MapToBoatDTO(sender.team.boat); response = ResponseMessageHelper.CreateResponse(HttpStatusCode.OK, false, boatDTO, ConstantResponse.TEAM_BOAT_GET_SUCCESS); } return(Request.CreateResponse <CustomResponse>(HttpStatusCode.OK, response)); }
public HttpResponseMessage Create([FromBody] Team team) { //Gets the user from token var token = Request.Headers.Authorization.Parameter; string userEmail = UserUtility.GetEmailByToken(token); CustomResponse response; using (M32COMDBSERVER DB = new M32COMDBSERVER()) { //Returns error if team name is not unique if (!_repository.IsTeamNameUnique(team.name)) { response = ResponseMessageHelper.CreateResponse(HttpStatusCode.BadRequest, true, null, ConstantResponse.TEAM_FAILED); return(Request.CreateResponse <CustomResponse>(HttpStatusCode.BadRequest, response)); } //Returns error if the user has already had a team bool userHasTeam = _repository.UserHasTeam(userEmail); if (userHasTeam) { response = ResponseMessageHelper.CreateResponse(HttpStatusCode.BadRequest, true, null, ConstantResponse.HAS_TEAM_ERR); return(Request.CreateResponse <CustomResponse>(HttpStatusCode.BadRequest, response)); } //Inserts the team Team insertedTeam = _repository.InsertTeam(userEmail, team); //Maps the team to its DTO TeamDTO teamDTO = GenericMapper.MapToTeamDTO(insertedTeam); response = ResponseMessageHelper.CreateResponse(HttpStatusCode.Created, false, teamDTO, ConstantResponse.TEAM_CREATED); return(Request.CreateResponse <CustomResponse>(HttpStatusCode.Created, response)); } }
public static List <FormTemplate> GetFakeSimpleFormTemplates() { User user = UserUtility.CreateUser("*****@*****.**", "John Smith"); List <FormTemplate> fakeTemplates = new List <FormTemplate> { new FormTemplate { Id = Guid.NewGuid(), Type = FormType.Quality, Subject = "Template 1", MustDisplayElementsCode = true, Creator = user }, new FormTemplate { Id = Guid.NewGuid(), Type = FormType.Safety, Subject = "Template 2", MustDisplayElementsCode = true, Creator = user }, new FormTemplate { Id = Guid.NewGuid(), Type = FormType.Quality, Subject = "Template 3", MustDisplayElementsCode = false, Creator = user }, new FormTemplate { Id = Guid.NewGuid(), Type = FormType.Safety, Subject = "Template 4", MustDisplayElementsCode = false, Creator = user }, new FormTemplate { Id = Guid.NewGuid(), Type = FormType.Environment, Subject = "Template 5", MustDisplayElementsCode = true, Creator = user } }; return(fakeTemplates); }