public IHttpActionResult GetMessage() { IList <ConversationViewModel> conversation = null; var CurrentuserId = RequestContext.Principal.Identity.GetUserId(); using (MitBudDBEntities mitBud = new MitBudDBEntities()) { //Table name (Comments) conversation = (from conv in mitBud.Conversations where conv.Client_Id == CurrentuserId select new ConversationViewModel() { TaskID = conv.Task_Id, Company_id = conv.Company_Id, Client_id = conv.Client_Id, Message = conv.Message }).ToList(); } if (conversation.Count == 0) { return(NotFound()); } return(Ok(conversation)); }
//Save Tasks to the database to the Tasks table public static void SaveTaskForLoggedInUser(TaskViewModel taskViewModel, string userId) { var regionName = Denmark_addressess.GetMunicipalityCode(taskViewModel.ClientStreetName, taskViewModel.ClientPostCode.ToString(), taskViewModel.ClientHouseNumber, taskViewModel.ClientCity); MitBudDBEntities db = new MitBudDBEntities(); Task Task = new Task(); Task.Title = taskViewModel.Title; Task.Client_id = userId; Task.Description = taskViewModel.Description; Task.Category = taskViewModel.Category; Task.ClientName = taskViewModel.ClientName; Task.ClientStreetName = taskViewModel.ClientStreetName; Task.ClientHouseNumber = taskViewModel.ClientHouseNumber; Task.ClientPostCode = taskViewModel.ClientPostCode; Task.Region = regionName; Task.ClientCity = taskViewModel.ClientCity; Task.ClientTelephone = taskViewModel.ClientTelephone; Task.ClientEmail = taskViewModel.ClientEmail; Task.WhoAreYou = taskViewModel.WhoAreYou; Task.TaskCost = taskViewModel.TaskCost; Task.Date = taskViewModel.Date; Task.DesiredDate = taskViewModel.DesiredDate; Task.Image = taskViewModel.Image; Task.Status = taskViewModel.Status; db.Tasks.Add(Task); db.SaveChanges(); }
public IHttpActionResult GetTask() { // var mitBud = new MitBudDBEntities(); IList <CompanyTaskViewModel> companyTaskVM = null; //List<string> ITEMS = new List<string>(); var CurrentuserId = RequestContext.Principal.Identity.GetUserId(); using (MitBudDBEntities mitBud = new MitBudDBEntities()) { companyTaskVM = (from task in mitBud.Tasks join c in mitBud.Companies on task.Region equals c.Region where c.Company_Category.Select(x => x.Name).Contains(task.Category) && c.Company_Category.Select(x => x.CompanyUserId).Contains(CurrentuserId) select new CompanyTaskViewModel() { TaskId = task.TaskId, Title = task.Title, Category = task.Category, ClientPostCode = task.ClientPostCode, Region = task.Region, ClientName = task.ClientName, Description = task.Description, }).Distinct().ToList(); } if (companyTaskVM.Count == 0) { return(NotFound()); } return(Ok(companyTaskVM)); }
//Save Task to the database in the Tasks table public static void SaveTaskRegisteredUser(TaskViewModel taskViewModel, string userId) { MitBudDBEntities db = new MitBudDBEntities(); Task Task = new Task(); Task.Client_id = userId; Task.Title = taskViewModel.Title; Task.Description = taskViewModel.Description; Task.Category = taskViewModel.Category; Task.ClientName = taskViewModel.ClientName; Task.ClientStreetName = taskViewModel.ClientStreetName; Task.ClientHouseNumber = taskViewModel.ClientHouseNumber; Task.ClientPostCode = taskViewModel.ClientPostCode; Task.Region = taskViewModel.Region; Task.ClientCity = taskViewModel.ClientCity; Task.ClientTelephone = taskViewModel.ClientTelephone; Task.ClientEmail = taskViewModel.ClientEmail; Task.WhoAreYou = taskViewModel.WhoAreYou; Task.TaskCost = taskViewModel.TaskCost; Task.Date = taskViewModel.Date; Task.DesiredDate = taskViewModel.DesiredDate; Task.Image = taskViewModel.Image; Task.Status = taskViewModel.Status; db.Tasks.Add(Task); db.SaveChanges(); //SendPasswordResetEmail(taskViewModel.ClientEmail, taskViewModel.ClientName); //ChangePasswordBindingModel ch = new ChangePasswordBindingModel(); //ch.OldPassword = randomPass; }
public IHttpActionResult GetClientTaskList() { IList <GetClientTaskListViewModel> taskViewModel = null; var CurrentuserId = RequestContext.Principal.Identity.GetUserId(); using (MitBudDBEntities mitBud = new MitBudDBEntities()) { taskViewModel = (from task in mitBud.Tasks where task.Client_id == CurrentuserId select new GetClientTaskListViewModel() { TaskId = task.TaskId, Title = task.Title, Description = task.Description, ClientStreetName = task.ClientStreetName, ClientHouseNumber = task.ClientHouseNumber, ClientPostCode = task.ClientPostCode, ClientCity = task.ClientCity, Region = task.Region, Status = task.Status, }).Distinct().ToList(); } if (taskViewModel.Count == 0) { return(NotFound()); } return(Ok(taskViewModel)); }
public async Task <HttpResponseMessage> Conversation(ConversationViewModel conversation) { MitBudDBEntities mitBudDB = new MitBudDBEntities(); var userId = RequestContext.Principal.Identity.GetUserId(); var CompanyEmail = mitBudDB.Companies.Where(x => x.UserId == userId).SingleOrDefault(); //var clientEmail = mitBudDB.Clients.Where(x => x.Client_Id == conversation.Client_id).SingleOrDefault(); var clientId = mitBudDB.Tasks.Where(x => x.TaskId == conversation.TaskID).SingleOrDefault(); //var companyName = CompanyEmail.CompanyName; CompanyProvider.SaveConversation(conversation, userId, clientId.Client_id); var statusCode = HttpStatusCode.Accepted; var responseMsg = new HttpResponseMessage(statusCode) { Content = new StringContent("", Encoding.UTF8, "application/json") }; Email.sendNotificationEmail(clientId.ClientName, clientId.ClientEmail, CompanyEmail.CompanyName); return(responseMsg); }
//Save Tasks to the database to the Tasks table //public static void SaveTask(TaskViewModel TaskViewModel) //{ // MitBudDBEntities db = new MitBudDBEntities(); // AspNetUser asp = new AspNetUser(); // Task Task = new Task(); // AccountController account = new AccountController(); // RegisterClient r = new RegisterClient(); // var s = r; // s.Name = TaskViewModel.ClientName; // s.Email = TaskViewModel.ClientEmail; // s.Password = "******"; // s.ConfirmPassword = "******"; // account.Register_client(r); // Task.Title = TaskViewModel.Title; // Task.Description = TaskViewModel.Description; // Task.Category = TaskViewModel.Category; // Task.ClientName = TaskViewModel.ClientName; // Task.ClientAddress = TaskViewModel.ClientName; // Task.ClientPostCode = TaskViewModel.ClientPostCode; // Task.ClientTelephone = TaskViewModel.ClientTelephone; // Task.ClientEmail = TaskViewModel.ClientEmail; // Task.WhoAreYou = TaskViewModel.WhoAreYou; // Task.TaskCost = TaskViewModel.TaskCost; // db.Tasks.Add(Task); // db.SaveChanges(); //} public static void SaveTask(TaskViewModel TaskViewModel, string userId) { MitBudDBEntities db = new MitBudDBEntities(); Task Task = new Task(); Task.Client_id = userId; Task.Title = TaskViewModel.Title; Task.Description = TaskViewModel.Description; Task.Category = TaskViewModel.Category; Task.ClientName = TaskViewModel.ClientName; Task.ClientAddress = TaskViewModel.ClientName; Task.ClientPostCode = TaskViewModel.ClientPostCode; Task.ClientTelephone = TaskViewModel.ClientTelephone; Task.ClientEmail = TaskViewModel.ClientEmail; Task.WhoAreYou = TaskViewModel.WhoAreYou; Task.TaskCost = TaskViewModel.TaskCost; db.Tasks.Add(Task); db.SaveChanges(); //SendPasswordResetEmail(TaskViewModel.ClientEmail, TaskViewModel.ClientName); //ChangePasswordBindingModel ch = new ChangePasswordBindingModel(); //ch.OldPassword = randomPass; }
public IHttpActionResult GetTask() { // var mitBud = new MitBudDBEntities(); IList <CompanyTaskViewModel> companyTaskVM = null; //List<string> ITEMS = new List<string>(); var CurrentuserId = RequestContext.Principal.Identity.GetUserId(); using (MitBudDBEntities mitBud = new MitBudDBEntities()) { companyTaskVM = (from task in mitBud.Tasks from Company_Category in mitBud.Company_Category where task.Category == Company_Category.Name && Company_Category.CompanyUserId == CurrentuserId from Company in mitBud.Companies where Company.PostCode == task.ClientPostCode select new CompanyTaskViewModel() { TaskId = task.TaskId, Title = task.Title, Category = task.Category, ClientPostCode = task.ClientPostCode, PostCode = Company.PostCode, ClientName = task.ClientName, Description = task.Description, }).Distinct().ToList(); } if (companyTaskVM.Count == 0) { return(NotFound()); } return(Ok(companyTaskVM)); }
public static void updateCredit(int?credit, string UserId) { MitBudDBEntities db = new MitBudDBEntities(); //Company company = new Company(); var findCompanyCredit = db.Companies.Where(x => x.UserId == UserId).SingleOrDefault(); findCompanyCredit.CompanyCredit = credit; db.SaveChanges(); }
public async Task <IHttpActionResult> NotRegisteredUserTask(TaskViewModel taskViewModel) { taskViewModel.Region = Denmark_addressess.GetMunicipalityCode(taskViewModel.ClientStreetName, taskViewModel.ClientPostCode.ToString(), taskViewModel.ClientHouseNumber, taskViewModel.ClientCity); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var randomPass = GenerateRandomPassword.GenerateRandomPass(); RegisterClient registerClient = new RegisterClient(); registerClient.Email = taskViewModel.ClientEmail; registerClient.Password = randomPass; registerClient.ConfirmPassword = randomPass; var user = new ApplicationUser() { UserName = taskViewModel.ClientEmail, Email = taskViewModel.ClientEmail }; IdentityResult result = await UserManager.CreateAsync(user, randomPass); if (result.Succeeded) { var UserId = UserManager.FindByEmail(taskViewModel.ClientEmail); ClientProvider.SaveClientInfo(taskViewModel.ClientName, taskViewModel.ClientEmail, UserId.Id); TaskProvider.SaveTaskRegisteredUser(taskViewModel, UserId.Id); UserManager.AddToRole(UserId.Id, "Client"); } if (!result.Succeeded) { return(GetErrorResult(result)); } var httpStatusCode = HttpStatusCode.Accepted; var responseMsg = new HttpResponseMessage(httpStatusCode) { Content = new StringContent("", Encoding.UTF8, "application/json") }; MitBudDBEntities mitBudDB = new MitBudDBEntities(); var UserEmail = mitBudDB.AspNetUsers.Where(x => x.Email == taskViewModel.ClientEmail).SingleOrDefault(); string token = await UserManager.GeneratePasswordResetTokenAsync(UserEmail.Id); Email.sendCreatePasswordByEmail(taskViewModel.ClientEmail, taskViewModel.ClientName, token); return(Ok()); }
public async Task <HttpResponseMessage> LoginUser(LoginUserBindingModel model) { // Invoke the "token" OWIN service to perform the login: /api/token // Ugly hack: I use a server-side HTTP POST because I cannot directly invoke the service (it is deeply hidden in the OAuthAuthorizationServerHandler class) var request = HttpContext.Current.Request; //To use locally //var tokenServiceUrl = "http://127.0.0.1:61902/Token"; var tokenServiceUrl = request.Url.GetLeftPart(UriPartial.Authority) + request.ApplicationPath + "/Token"; using (var client = new HttpClient()) { var requestParams = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("grant_type", "password"), new KeyValuePair <string, string>("username", model.Username), new KeyValuePair <string, string>("password", model.Password) }; var requestParamsFormUrlEncoded = new FormUrlEncodedContent(requestParams); var tokenServiceResponse = await client.PostAsync(tokenServiceUrl, requestParamsFormUrlEncoded); var responseString = await tokenServiceResponse.Content.ReadAsStringAsync(); var responseCode = tokenServiceResponse.StatusCode; var responseMsg = new HttpResponseMessage(responseCode) { Content = new StringContent(responseString, Encoding.UTF8, "application/json") }; if (responseCode == HttpStatusCode.OK) { MitBudDBEntities mitBudDB = new MitBudDBEntities(); var Bodyresponse = mitBudDB.AspNetUsers.FirstOrDefault(X => X.Email == model.Username); // Get the roles associated with that user var userRoles = await UserManager.GetRolesAsync(Bodyresponse.Id.ToString()); // Setup a RoleViewModel list of roles and iterate through userRoles adding them to the list List <RoleViewModel> roleList = new List <RoleViewModel>(); foreach (var role in userRoles) { var item = new RoleViewModel { Role = role }; roleList.Add(item); //return Ok(item); var res = responseMsg; } } return(responseMsg); } }
public static void SaveCategory(RegisterCompany registerViewModel, string UserId) { MitBudDBEntities db = new MitBudDBEntities(); Company_Category company_category = new Company_Category(); company_category.CompanyUserId = UserId; company_category.Name = registerViewModel.Category; db.Company_Category.Add(company_category); db.SaveChanges(); }
public static void SaveConversation(ConversationViewModel conversation, string UserId) { MitBudDBEntities db = new MitBudDBEntities(); Task task = new Task(); Conversation con = new Conversation(); con.Company_Id = UserId; con.Message = conversation.Message; con.Client_Id = conversation.Client_id; db.Conversations.Add(con); db.SaveChanges(); }
public static void SaveClientInfo(RegisterClient registerViewModel, string UserId) { MitBudDBEntities db = new MitBudDBEntities(); Client client = new Client(); client.Client_Id = UserId; client.Name = registerViewModel.Name; client.Email = registerViewModel.Email; db.Clients.Add(client); db.SaveChanges(); }
public static void SaveTaskStatus(int TaskId, string userId, int?status) { MitBudDBEntities db = new MitBudDBEntities(); var findTaskId = db.Tasks.Where(x => x.TaskId == TaskId).SingleOrDefault(); //Task task = new Task(); findTaskId.Status = status; // db.Tasks.Add(task); db.SaveChanges(); }
public static void SaveCompanyInfo(RegisterCompany registerViewModel, string UserId) { MitBudDBEntities db = new MitBudDBEntities(); Company company = new Company(); company.UserId = UserId; company.CompanyName = registerViewModel.CompanyName; company.Telephone = registerViewModel.Telephone; company.CompanySize = registerViewModel.CompanySize; company.City = registerViewModel.City; company.CVR = registerViewModel.CVR; company.Email = registerViewModel.Email; company.ContactPerson = registerViewModel.ContactPerson; company.Address = registerViewModel.Address; company.PostCode = registerViewModel.PostCode; db.Companies.Add(company); db.SaveChanges(); }
//Save Tasks to the database to the Tasks table //public static void SaveTask(TaskViewModel TaskViewModel) //{ // MitBudDBEntities db = new MitBudDBEntities(); // AspNetUser asp = new AspNetUser(); // Task Task = new Task(); // AccountController account = new AccountController(); // RegisterClient r = new RegisterClient(); // var s = r; // s.Name = TaskViewModel.ClientName; // s.Email = TaskViewModel.ClientEmail; // s.Password = "******"; // s.ConfirmPassword = "******"; // account.Register_client(r); // Task.Title = TaskViewModel.Title; // Task.Description = TaskViewModel.Description; // Task.Category = TaskViewModel.Category; // Task.ClientName = TaskViewModel.ClientName; // Task.ClientAddress = TaskViewModel.ClientName; // Task.ClientPostCode = TaskViewModel.ClientPostCode; // Task.ClientTelephone = TaskViewModel.ClientTelephone; // Task.ClientEmail = TaskViewModel.ClientEmail; // Task.WhoAreYou = TaskViewModel.WhoAreYou; // Task.TaskCost = TaskViewModel.TaskCost; // db.Tasks.Add(Task); // db.SaveChanges(); //} //public string codd(string a) //{ // return a; //} public static void SaveTask(TaskViewModel TaskViewModel) { AccountController account = new AccountController(); var randomPass = GenerateRandomPassword(); RegisterClient r = new RegisterClient(); var s = r; s.Email = TaskViewModel.ClientEmail; s.Name = TaskViewModel.ClientName; s.Password = randomPass; s.ConfirmPassword = randomPass; account.Register_client(r); MitBudDBEntities db = new MitBudDBEntities(); Task Task = new Task(); Task.Title = TaskViewModel.Title; Task.Description = TaskViewModel.Description; Task.Category = TaskViewModel.Category; Task.ClientName = TaskViewModel.ClientName; Task.ClientAddress = TaskViewModel.ClientName; Task.ClientPostCode = TaskViewModel.ClientPostCode; Task.ClientTelephone = TaskViewModel.ClientTelephone; Task.ClientEmail = TaskViewModel.ClientEmail; Task.WhoAreYou = TaskViewModel.WhoAreYou; Task.TaskCost = TaskViewModel.TaskCost; db.Tasks.Add(Task); db.SaveChanges(); // SendPasswordResetEmail(TaskViewModel.ClientEmail, TaskViewModel.ClientName); //ChangePasswordBindingModel ch = new ChangePasswordBindingModel(); //ch.OldPassword = randomPass; }
//Save Tasks to the database to the Tasks table public static void SaveTaskLoggedIn(TaskViewModel TaskViewModel, string userId) { GenerateRandomPassword(); MitBudDBEntities db = new MitBudDBEntities(); Task Task = new Task(); Task.Title = TaskViewModel.Title; Task.Client_id = userId; Task.Description = TaskViewModel.Description; Task.Category = TaskViewModel.Category; Task.ClientName = TaskViewModel.ClientName; Task.ClientAddress = TaskViewModel.ClientName; Task.ClientPostCode = TaskViewModel.ClientPostCode; Task.ClientTelephone = TaskViewModel.ClientTelephone; Task.ClientEmail = TaskViewModel.ClientEmail; Task.WhoAreYou = TaskViewModel.WhoAreYou; Task.TaskCost = TaskViewModel.TaskCost; db.Tasks.Add(Task); db.SaveChanges(); }
public async Task <IHttpActionResult> CreatePassword(CreatePasswordBindingModel model) { MitBudDBEntities mitBudDB = new MitBudDBEntities(); var UserEmail = mitBudDB.AspNetUsers.Where(x => x.Email == model.Email).SingleOrDefault(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await UserManager.ResetPasswordAsync(UserEmail.Id, model.token, model.NewPassword); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); }
public IHttpActionResult CompanyCredit() { MitBudDBEntities mitBud = new MitBudDBEntities(); var userId = RequestContext.Principal.Identity.GetUserId(); var findCompanyCredit = mitBud.Companies.Where(x => x.UserId == userId).SingleOrDefault(); if (findCompanyCredit != null) { var substractCompanyCredit = findCompanyCredit.CompanyCredit = findCompanyCredit.CompanyCredit - 1; if (substractCompanyCredit > -1) { CompanyProvider.updateCredit(substractCompanyCredit, userId); } else { return(Content(HttpStatusCode.BadRequest, "You have no credit left")); } } else { return(NotFound()); } return(Ok()); // var dd = HttpStatusCode.Accepted; // var responseMsg = new HttpResponseMessage(dd) // { // Content = new StringContent("", Encoding.UTF8, "application/json") // }; //} }