public async Task <ActionResult <user> > Postusers(user u) { _context.users.Add(u); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Getusers), new { id = u.Id }, u)); }
public async Task <IActionResult> PutAccount(int id, Account account) { if (id != account.id) { return(BadRequest()); } _context.Entry(account).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <hardware> > Posthardware(hardware u) { _context.hardware.Add(u); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Gethardware), new { id = u.Id }, u)); }
public async Task <ActionResult <user> > Postsoftware(software u) { _context.software.Add(u); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Getsoftware), new { id = u.Id }, u)); }
public async Task <IHttpActionResult> ContrairBracoDireito() { try { var bDireito = db.BracoDireitoes.ToList().LastOrDefault(); if (bDireito.Cotovelo <= 2) { BracoDireito item = new BracoDireito(); item.Cotovelo = bDireito.Cotovelo + 1; item.Pulso = bDireito.Pulso; db.BracoDireitoes.Add(item); await db.SaveChangesAsync(); return(Ok(GetSituacaoAtual())); } return(BadRequest()); } catch (WebException we) { return(BadRequest(we.Message)); } }
public async Task <IHttpActionResult> RotacaoCabeca() { try { var cabeca = db.Cabecas.ToList().LastOrDefault(); if (cabeca.Inclinacao > -1 && cabeca.Rotacao < 90) { Cabeca item = new Cabeca(); item.Inclinacao = cabeca.Inclinacao; item.Rotacao = cabeca.Rotacao + 45; db.Cabecas.Add(item); await db.SaveChangesAsync(); return(Ok(GetSituacaoAtual())); } return(BadRequest()); } catch (WebException we) { return(BadRequest(we.Message)); } }
public async Task <IHttpActionResult> Get() { try { var allCabeca = db.Cabecas.ToList(); var allBEsquerdo = db.BracoDireitoes.ToList(); var allBDireito = db.BracoEsquerdoes.ToList(); if (allCabeca.Count == 0) { Cabeca item = new Cabeca(); item.Inclinacao = 0; item.Rotacao = 0; db.Cabecas.Add(item); await db.SaveChangesAsync(); } if (allBEsquerdo.Count == 0) { BracoEsquerdo item = new BracoEsquerdo(); item.Cotovelo = 0; item.Pulso = 0; db.BracoEsquerdoes.Add(item); await db.SaveChangesAsync(); } if (allBDireito.Count == 0) { BracoDireito item = new BracoDireito(); item.Cotovelo = 0; item.Pulso = 0; db.BracoDireitoes.Add(item); await db.SaveChangesAsync(); } var cabeca = db.Cabecas.ToList().LastOrDefault(); var bDireito = db.BracoDireitoes.ToList().LastOrDefault(); var bEsquerdo = db.BracoEsquerdoes.ToList().LastOrDefault(); Robo robo = new Robo(); robo.cabeca = cabeca; robo.bracoDireito = bDireito; robo.bracoEsquerdo = bEsquerdo; return(Ok(robo)); } catch (WebException we) { return(BadRequest(we.Message)); } }
public async Task <ActionResult <UserDTO> > register(RegisterDTO reg) { if (await isExist(reg.name)) { return(BadRequest("User Name Is Exist, Please try another name")); } using var hmack = new HMACSHA512(); var user = new user { Username = reg.name.ToLower(), passwordHash = hmack.ComputeHash(Encoding.UTF8.GetBytes(reg.password)), passwordSalt = hmack.Key }; db.Add(user); await db.SaveChangesAsync(); return(new UserDTO { name = user.Username, token = await jwt.createToken(user) }); }
/// <summary> /// POST METHOD TO RECEIVE AN OBJECT WITH USER NAME AND EMAIL ADDRESS, /// AND TO SEND A CONFIRMATION EMAIL TO THE EMAIL ADDRESS /// </summary> /// <param name="subusers"></param> /// <returns> STRING TO THE AJAX CALL </returns> public async Task <JsonResult> SubmitDetails(Subusers subusers) { //if the email address is null then return NA else continue if (subusers.Uemail == null) { return(Json("NA")); } //check for the email address in the context var useremail = subusers.Uemail; var existingUser = _context.Subusers.Any(x => x.Uemail.Equals(useremail)); //if email address exists then return Y else continue if (existingUser) { return(Json("Y")); } //create an object to insert the values in the context Subusers UD = new Subusers(); UD.Uname = subusers.Uname; UD.Uemail = subusers.Uemail; //add to the dataset _context.Subusers.Add(UD); //create an instance of smtpclient SmtpClient smtpClient = new SmtpClient { Host = "smtp.gmail.com", //Host = "smtp-mail.outlook.com", Port = 587, EnableSsl = true, Credentials = new NetworkCredential("*****@*****.**", "Sandbox_test") }; try { //prepare the email message using (var message = new MailMessage("*****@*****.**", useremail) { Subject = "Subscription successful", Body = "Dear " + subusers.Uname + ", \n \n \t Thank you For Subscribing \n \n - AlgoDepth. \n \n \n PLEASE DO NOT RESPOND TO THIS EMAIL, this account is not monitored!" }) //send the messsage await smtpClient.SendMailAsync(message); //save the changes in the database await _context.SaveChangesAsync(); } //catch exception if any catch (Exception e) { return(Json(e)); } //return N - indicating new user is added return(Json("N")); }