public async Task <JsonResult> Post([FromForm] CompanyHelper company) { //Viewmodel validations if (!ModelState.IsValid) { return(new JsonResult(ModelState) { StatusCode = (int)HttpStatusCode.BadRequest }); } string picture = await _imageHandler.UploadImage(company.Logo); //Creating the entity var _company = new Company() { Description = company.Description, Name = company.Name, Logo = picture }; //Finally add await _context.Companies.AddAsync(_company); await _context.SaveChangesAsync(); return(new JsonResult(_company) { StatusCode = (int)HttpStatusCode.OK }); }
public async Task <IActionResult> Post([FromForm] ProductHelper product) { int companyId = int.Parse(GetTokenReadable().GetCompanyId()); //Viewmodel validations if (!ModelState.IsValid) { return(new JsonResult(ModelState) { StatusCode = (int)HttpStatusCode.BadRequest }); } var company = await _context.Accounts.FindAsync(companyId); if (company == null) { return(new JsonResult ("Company doesn't exist or has been deleted") { StatusCode = (int)HttpStatusCode.NotFound }); } //Creating the entity var _product = new Product() { ProductId = product.Id, Description = product.Description, Name = product.Name, Price = product.Price, Account = company, Stock = product.Stock, Ecommerce = product.Ecommerce }; if (product.Picture != null) { string picture = await _imageHandler.UploadImage(product.Picture); _product.Picture = picture; } else { _product.Picture = "productdefault.png"; } //Finally add await _context.Products.AddAsync(_product); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Post([FromForm] EmployeeHelper employee) { int companyId = int.Parse(GetTokenReadable().GetCompanyId()); //Viewmodel validations if (!ModelState.IsValid) { return(new JsonResult(ModelState) { StatusCode = (int)HttpStatusCode.BadRequest }); } var company = await _context.Accounts.FindAsync(companyId); if (company == null) { return(new JsonResult ("Company doesn't exist or has been deleted") { StatusCode = (int)HttpStatusCode.NotFound }); } //Creating the entity var _employee = new Employee() { Name = employee.Name, Email = employee.Email, Cellphone = employee.Cellphone, DocumentNumber = employee.DocumentNumber, Description = employee.Description, Account = company }; if (employee.Picture != null) { string picture = await _imageHandler.UploadImage(employee.Picture); _employee.Picture = picture; } else { _employee.Picture = "employeedefault.png"; } //Finally add await _context.Employees.AddAsync(_employee); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <JsonResult> Post([FromBody] AccountHelper account, int id) { //Test string jwt = Request.Headers["Authorize"]; if (!ModelState.IsValid) { return(new JsonResult(ModelState) { StatusCode = (int)HttpStatusCode.BadRequest }); } var plan = await _context.Plans.FindAsync(id); if (plan == null) { return(new JsonResult ("Company doesn't exist or has been deleted") { StatusCode = (int)HttpStatusCode.NotFound }); } var _account = new Account() { Features = account.Features }; await _context.Accounts.AddAsync(_account); await _context.SaveChangesAsync(); return(new JsonResult(_account) { StatusCode = (int)HttpStatusCode.OK }); }
public async Task <IActionResult> Post([FromBody] SalesHelper _sale) { if (!ModelState.IsValid) { return(new JsonResult(ModelState) { StatusCode = (int)HttpStatusCode.BadRequest }); } var costumer = await _context.Customers.FindAsync(_sale.CustomerId); var sale = new Sale() { Date = DateTime.Now, Type = "Contado", Code = "1", Customer = costumer, }; var saleRegistered = await _context.Sales.AddAsync(sale); foreach (var i in _sale.ProductsBought) { var product = await _context.Products.FindAsync(i.id); var productBought = new SpecsProduct() { Product = product, Description = "hola mundo", Sale = sale }; await _context.SpecsProduct.AddAsync(productBought); await _context.SaveChangesAsync(); } return(Ok(sale.SaleId)); }
public async Task <JsonResult> Post([FromBody] EventHelper myEvent) { int companyId = int.Parse(GetTokenReadable().GetCompanyId()); //Viewmodel validations if (!ModelState.IsValid) { return(new JsonResult(ModelState) { StatusCode = (int)HttpStatusCode.BadRequest }); } var company = await _context.Accounts.FindAsync(companyId); //Creating the entity var _event = new Event() { description = myEvent.description, title = myEvent.title, start = myEvent.start ?? DateTime.Now, end = myEvent.end ?? DateTime.Now.AddDays(1), Company = company }; var newEvent = await _context.Events.AddAsync(_event); await _context.SaveChangesAsync(); /* * var twilio = new TwilioHelper (); * * twilio.sendMessage(" Se ha registrado el evento de '"+_event.title+"' de la empresa del dia " + _event.start.ToString("dd/MM/yyyy HH:mm:ss") + " al día " + _event.end.ToString("dd/MM/yyyy HH:mm:ss") ); */ return(new JsonResult("Ingresado Correctamente") { StatusCode = (int)HttpStatusCode.OK }); }
public async Task <IActionResult> SetfromInterview(int id) { int companyId = int.Parse(GetTokenReadable().GetCompanyId()); //Move employee from interview to employee //Get interview entitie var selected = _context.Interviews.FirstOrDefault(e => e.InterviewId == id); var toInsert = new Employee() { Name = selected.FullName, DocumentNumber = selected.DocumentNumber, Email = selected.Email }; await _context.Employees.AddAsync(toInsert); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Post([FromBody] CustomerHelper customer, int id) { if (!ModelState.IsValid) { return(new JsonResult(ModelState) { StatusCode = (int)HttpStatusCode.BadRequest }); } var account = await _context.Accounts.FindAsync(id); /* * if (account == null) * { * return new JsonResult * ("Company doesn't exist or has been deleted") * { StatusCode = (int)HttpStatusCode.Conflict }; * } */ var _customer = new Customer() { Name = customer.Name, Email = customer.Email, Document = customer.Document, Cellphone = customer.Cellphone, Account = account }; await _context.Customers.AddAsync(_customer); await _context.SaveChangesAsync(); return(Ok()); }