// GET: api/Manufacturers public HttpResponseMessage GetManufacturer() { List <ManufacturerDTO> ListOfManufacturers = new List <ManufacturerDTO>(); foreach (var item in repo.GetManufacturers()) { ListOfManufacturers.Add(TheDTOFactory.Create(item)); } return(Request.CreateResponse(HttpStatusCode.OK, ListOfManufacturers)); }
// GET: api/Categories public HttpResponseMessage GetCategory() { List <CategoryDTO> ListOfCategory = new List <CategoryDTO>(); foreach (var item in repo.GetCategory()) { ListOfCategory.Add(TheDTOFactory.Create(item)); } return(Request.CreateResponse(HttpStatusCode.OK, ListOfCategory)); }
public HttpResponseMessage GetManufacturer(string name) { var manufacturer = repo.GetManufacturer(name); if (manufacturer == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "the category is not found")); } var factoryManufacturer = TheDTOFactory.Create(manufacturer); return(Request.CreateResponse(HttpStatusCode.OK, factoryManufacturer)); }
public HttpResponseMessage GetCategory(int id) { var category = repo.GetCategory(id); if (category == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Category not found")); } var factoryCategory = TheDTOFactory.Create(category); return(Request.CreateResponse(HttpStatusCode.OK, factoryCategory)); }
public HttpResponseMessage GetProduct(int id) { // find the product from the repo + database Product productFound = repo.getProductById(id); if (productFound == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Product not found")); } ProductDTO productfactoried = TheDTOFactory.Create(productFound); return(Request.CreateResponse(HttpStatusCode.OK, productfactoried)); }
public HttpResponseMessage GetApiKey(string email, string password) { var getUser = repo.getApiKey(email, password); var user = db.Users.First(x => x.Email == email); if (user != null) { if (Crypto.VerifyHashedPassword(user.Password, password)) { FormsAuthentication.SetAuthCookie(user.Email, true); } } if (getUser == null) { return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Invalid Email or Password")); } if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (getUser.ApiKey == null) { try { getUser.ApiKey = GetApiKey(); db.Entry(getUser).State = EntityState.Modified; //db.Entry(getUser).CurrentValues.SetValues(getUser); db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Failed to save API key to database")); } } var response = Request.CreateResponse(HttpStatusCode.OK); response.Headers.Add("xcmps383authenticationid", getUser.UserId.ToString()); response.Headers.Add("xcmps383authenticationkey", getUser.ApiKey); return(Request.CreateResponse(HttpStatusCode.OK, TheDTOFactory.Create(getUser.ApiKey, getUser.UserId))); // return response; }
public HttpResponseMessage GetProducts() { // if (IsAuthorized(Request, new List<Role> { Role.Admin })) //{ List <ProductDTO> ProductList = new List <ProductDTO>(); foreach (var item in repo.GetAllProducts()) { ProductList.Add(TheDTOFactory.Create(item)); } return(Request.CreateResponse(HttpStatusCode.OK, ProductList)); // } // return Request.CreateResponse(HttpStatusCode.Unauthorized); }
public HttpResponseMessage PutProduct([FromBody] Product product) { if (ModelState.IsValid) { repo.createProduct(product); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, product); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = product.ProductId })); ProductDTO productfactoried = TheDTOFactory.Create(product); return(Request.CreateResponse(HttpStatusCode.OK, productfactoried)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }