예제 #1
0
        public Boat AddBoat(int leaderId, Boat boat)
        {
            Team team = GetTeamByLeaderId(leaderId);

            boat.teamId = team.id;
            team.boat   = boat;
            DB.SaveChanges();

            return(boat);
        }
예제 #2
0
        public HttpResponseMessage Quit()
        {
            //Gets the user from token
            var            token     = Request.Headers.Authorization.Parameter;
            string         userEmail = UserUtility.GetEmailByToken(token);
            CustomResponse response;



            try
            {
                using (M32COMDBSERVER DB = new M32COMDBSERVER())
                {
                    User loginUser = DB.Users.Include(x => x.receivedNotification).Include(x => x.team).Include(x => x.team.boat).First(x => x.email == userEmail);
                    if (loginUser.team == null)
                    {
                        response = ResponseMessageHelper.CreateResponse(HttpStatusCode.BadRequest, true, null, ConstantResponse.TEAM_QUIT_FAILED);
                        return(Request.CreateResponse <CustomResponse>(HttpStatusCode.BadRequest, response));
                    }
                    Team team = DB.Teams.Include(x => x.teamMembers).Where(x => x.id == loginUser.teamId).First();

                    //Team leader disposes the team
                    if (team.leaderId == loginUser.id)
                    {
                        DB.Teams.Remove(team);
                        DB.SaveChanges();
                        response = ResponseMessageHelper.CreateResponse(HttpStatusCode.OK, false, null, ConstantResponse.TEAM_DISPOSED);
                        return(Request.CreateResponse <CustomResponse>(HttpStatusCode.OK, response));
                    }
                    //Person quits from the team
                    team.teamMembers.Remove(loginUser);
                    DB.Entry(team).State      = EntityState.Modified;
                    DB.Entry(loginUser).State = EntityState.Modified;
                    DB.SaveChanges();
                    response = ResponseMessageHelper.CreateResponse(HttpStatusCode.OK, false, ConstantResponse.OK, ConstantResponse.TEAM_QUIT_SUCCESS);
                    return(Request.CreateResponse <CustomResponse>(HttpStatusCode.OK, response));
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
예제 #3
0
        public void UpdateTeam(string email, int?teamId)
        {
            User user = GetByEmail(email);

            user.teamId = teamId;
            DB.Users.Attach(user);
            DB.Entry(user).Property(x => x.teamId).IsModified = true;
            DB.SaveChanges();
        }
예제 #4
0
 // After an Action Runs
 public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
 {
     using (M32COMDBSERVER context = new M32COMDBSERVER())
     {
         context.Logs.Add(new Log()
         {
             isBefore   = false,
             logCaption = $"{actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor.ControllerName} - {actionExecutedContext.ActionContext.ActionDescriptor.ActionName}",
             time       = DateTime.Now,
             logDetail  = (actionExecutedContext.Response.Content as ObjectContent).ObjectType.FullName
         });
         context.SaveChanges();
     }
     base.OnActionExecuted(actionExecutedContext);
 }
예제 #5
0
		public void Apply(int competitionId, int? teamId)
		{
			Team team = DB.Teams.Where(x => x.id == teamId).FirstOrDefault();
			Competition competition = GetById(competitionId);
			TeamCompetition teamComp = new TeamCompetition();

			teamComp.competition = competition;
			teamComp.competitionId = competition.id;
			teamComp.team = team;
			teamComp.teamId = team.id;
			teamComp.finishTime = CompetitionUtility.GetRandomDay(competition.startDate, competition.endDate);

			DB.TeamCompetitions.Add(teamComp);
			DB.SaveChanges();
		}
예제 #6
0
        //Inserts user if the user's email is not in use.
        public User Register(User user)
        {
            //Random salt is created
            var salt = PasswordHashingUtility.GenerateSalt();

            //Hash is created by using random salt and password
            user.password     = PasswordHashingUtility.GenerateSaltedHash(user.password, salt);
            user.passwordSalt = salt;

            if (DB.Users.Any(x => x.email == user.email))
            {
                return(null);
            }

            DB.Users.Add(user);
            DB.SaveChanges();
            return(user);
        }
예제 #7
0
 // Before an Action Runs
 public override void OnActionExecuting(HttpActionContext actionContext)
 {
     using (M32COMDBSERVER context = new M32COMDBSERVER())
     {
         StringBuilder sb = new StringBuilder();
         foreach (var item in actionContext.ActionArguments)
         {
             sb.Append($"{item.Key}={item.Value.ToString()},");
         }
         context.Logs.Add(new Log()
         {
             isBefore   = true,
             logCaption = $"{actionContext.ControllerContext.ControllerDescriptor.ControllerName} - {actionContext.ActionDescriptor.ActionName}",
             time       = DateTime.Now,
             logDetail  = sb.ToString()
         });
         context.SaveChanges();
     }
     base.OnActionExecuting(actionContext);
 }
 //Inserts the notificiation to the DB
 public void Insert(Notification notification)
 {
     DB.Notifications.Add(notification);
     DB.SaveChanges();
 }