/// <summary> /// Constructor /// </summary> public override void OnActionExecuting(HttpActionContext context) { var header = context.Request.Headers.SingleOrDefault(x => x.Key == "scheduler"); bool valid = false; JSendMessage json; if (header.Value == null) { valid = false; } else { if (header.Value.ToArray()[0].Equals("pollWebApi123")) { valid = true; } } if (!valid) { // Token invalid json = new JSendMessage("fail", "Invalid Authorization Key"); context.Response = context.Request.CreateResponse(HttpStatusCode.Forbidden, json); } }
public HttpResponseMessage Voted(string id) { HttpResponseMessage responseMessage; JSend json; int[] pageVal = GetPageNumberAndElementNumber(); int page_nr = pageVal[0]; int per_page = pageVal[1]; string state = GetState(); List <FormDTO> list = new List <FormDTO>(); list = formModel.GetVotedForms(id, page_nr, per_page, state); if (list.Count > 0) { json = new JSendData <FormDTO>("success", list); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "No items found"); responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json); } return(responseMessage); }
/// <summary> /// Constructor /// </summary> public override void OnActionExecuting(HttpActionContext context) { var authModel = new AuthModel(); var header = context.Request.Headers.SingleOrDefault(x => x.Key == "token"); bool valid; if (header.Value == null) { valid = false; } else { // Tokenul apartine unui admin var isAdmin = authModel.VerifyAdminToken(header.Value.First()); // Tokenul este valid var okDate = authModel.VerifyToken(header.Value.First()); valid = isAdmin && okDate; } if (!valid) { var json = new JSendMessage("fail", "Invalid Authorization Key"); context.Response = context.Request.CreateResponse(HttpStatusCode.Forbidden, json); } }
/// <summary> /// Constructor /// </summary> public override void OnActionExecuting(HttpActionContext context) { AuthModel authModel = new AuthModel(); FormModel formModel = new FormModel(); JSendMessage json; var header = context.Request.Headers.SingleOrDefault(x => x.Key == "token"); var formIdToDelete = context.Request.RequestUri.Segments[3]; bool valid = false, isAdmin = false, okDate = false, formIsFromUser = false; if (header.Value == null) { valid = false; } else { // Tokenul apartine unui admin isAdmin = authModel.VerifyAdminToken(header.Value.First()); // Tokenul este valid okDate = authModel.VerifyToken(header.Value.First()); valid = isAdmin && okDate; // Tokenul si sondajul apartin aceluiasi user formIsFromUser = formModel.FormIdCreatedbyUserId(Int32.Parse(formIdToDelete), header.Value.First()); } if (!(valid || formIsFromUser)) { // Token invalid json = new JSendMessage("fail", "Invalid Authorization Key"); context.Response = context.Request.CreateResponse(HttpStatusCode.Forbidden, json); } }
public HttpResponseMessage Post(TokenDTO token) { HttpResponseMessage responseMessage; bool valid; if (token.Token == null) { valid = false; } else { valid = auth.VerifyTokenDate(token.Token); // valid = true; } if (!valid) { // Token invalid var json = new JSendMessage("fail", "Invalid Authorization Key"); responseMessage = Request.CreateResponse(HttpStatusCode.Forbidden, json); } else { string role = tokens.GetRoleByToken(token.Token); // string role = "admin"; var json = new RoleMessage(role); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } return(responseMessage); }
public async Task <HttpResponseMessage> DeleteProducts(int id) { HttpResponseMessage responseMessage; try { Products products = await db.Products.FindAsync(id); if (products == null) { responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest); return(responseMessage); } db.Products.Remove(products); await db.SaveChangesAsync(); } catch (Exception) { responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest); return(responseMessage); } var json = new JSendMessage("success", "Product successfully removed"); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); return(responseMessage); }
public HttpResponseMessage EditOrders(UpdateOrderDTO request) { HttpResponseMessage responseMessage; JSendMessage json; var order = db.Orders.FirstOrDefault(o => o.OrderId == request.OrderId); if (null != order) { order.Sent = request.Sent; db.Orders.Update(order); db.SaveChanges(); json = new JSendMessage("success", "Order successfully updated"); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("success", "Order not found"); responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json); } return(responseMessage); }
public HttpResponseMessage Get() { HttpResponseMessage responseMessage; JSend json; string token = Request.Headers.SingleOrDefault(x => x.Key == "token").Value.First(); int[] pageVal = GetPageNumberAndElementNumber(); int page_nr = pageVal[0]; int per_page = pageVal[1]; string state = GetState(); List <FormDTO> list = formModel.GetAllForms(token, page_nr, per_page, state); if (list.Count > 0) { json = new JSendData <FormDTO>("success", list); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "No items found"); responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json); } return(responseMessage); }
public HttpResponseMessage Get(string id) { HttpResponseMessage responseMessage; JSend json; var token = Request.Headers.SingleOrDefault(x => x.Key == "token").Value.First(); var pageVal = GetPageNumberAndElementNumber(); var pageNr = pageVal[0]; var perPage = pageVal[1]; var state = GetState(); var list = new List <UtilityDTO>(); list = _carsUtilitiesModel.GetAllUtilities(null); if (list.Count > 0) { json = new JSendData <UtilityDTO>("success", list); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "No items found"); responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json); } return(responseMessage); }
// GET: api/Orders/5 public HttpResponseMessage GetOrders(int orderId, string lang) { HttpResponseMessage responseMessage; JSend json; var token = Request.Headers.SingleOrDefault(x => x.Key == "token").Value.First(); var userId = db.Tokens.First(u => u.TokenString.Equals(token))?.UserId; var order = db.Orders.FirstOrDefault(o => o.OrderId == orderId && o.UserId == userId); if (order != null) { var productsOrdersList = db.ProductsOrders.Where(o => o.OrderId == order.OrderId); var productList = productsOrdersList.Select(product => db.Products.FirstOrDefault(p => p.ProductId == product.ProductId && product.OrderId == order.OrderId)).ToList(); var result = new GetOrderDTO() { UserDetails = new UserUpdateDetails { FirstName = order.FirstName, LastName = order.LastName, State = order.State, StreetAddress = order.Address, City = order.City, ZipCode = order.ZipCode, Phone = order.Phone, Email = order.Email }, PaymentMethod = order.PaymentMethod, Currency = order.Currency, Subtotal = order.Subtotal, Shipping = order.Shipping, Products = new List <OrderProductInfo>(), Invoice = order.Invoice, Sent = order.Sent }; foreach (var product in productList) { var productsOrder = productsOrdersList.FirstOrDefault(p => p.ProductId == product.ProductId); result.Products.Add(new OrderProductInfo { Name = ComputeName(product, lang), Price = productsOrder.ProductPrice, ProductId = product.ProductId, Amount = productsOrder.Amount, Image = new ProductsImagesController().GetProductsImage(product.ProductId) }); } responseMessage = Request.CreateResponse(HttpStatusCode.OK, result); } else { json = new JSendMessage("fail", "No items found"); responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json); } return(responseMessage); }
public HttpResponseMessage Get() { var model = new UsersModel(); model.ScheduleUpdates(); JSend json = new JSendMessage("success", "Database successfully updated"); var responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); return(responseMessage); }
public HttpResponseMessage PostProducts() { HttpResponseMessage responseMessage; try { var httpRequest = HttpContext.Current.Request; var productToAdd = Newtonsoft.Json.JsonConvert.DeserializeObject <Products>(httpRequest.Form["data"]); db.Products.Add(productToAdd); db.SaveChanges(); foreach (string fileName in httpRequest.Files) { var postedFile = httpRequest.Files[fileName]; Stream fs = postedFile.InputStream; BinaryReader br = new BinaryReader(fs); var bytes = br.ReadBytes((int)fs.Length); using (Stream memStream = new MemoryStream(bytes)) { using (Image img = Image.FromStream(memStream)) { ProductsImages imageEntity = new ProductsImages() { Id = Guid.NewGuid(), Name = Encoding.ASCII.GetBytes(postedFile.FileName), Data = bytes, Width = img.Width, Height = img.Height, Length = bytes.Length, ContentType = postedFile.ContentType, ProductId = productToAdd.ProductId, Date = DateTime.Now }; db.ProductsImages.Add(imageEntity); } db.SaveChanges(); } } } catch (DbUpdateException) { responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest); return(responseMessage); } var json = new JSendMessage("success", "Product successfully added"); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); return(responseMessage); }
public HttpResponseMessage Post(UserRegistration user) { HttpResponseMessage response; JSendMessage json; var userAddress = new UsersAddresses { Address = user.StreetAddress, City = user.City, ZipCode = user.ZipCode, State = user.State }; var userDetails = new Users { UserId = 0, Email = user.Email, Password = user.Password, FirstName = user.FirstName, LastName = user.LastName, Phone = user.Phone, Role = "user", Verified = "no", UsersAddresses = new List <UsersAddresses> { userAddress } }; using (TransactionScope transaction = new TransactionScope()) { var UsersLogic = new UsersLogic(db); var added = UsersLogic.AddUser(userDetails); if (added) { db.SaveChanges(); transaction.Complete(); json = new JSendMessage("success", "Registration was successful! Please, verify your mail address."); response = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("failed", "Registration failed! Please, try another email."); response = Request.CreateResponse(HttpStatusCode.Forbidden, json); } } return(response); }
public HttpResponseMessage Get(int id) { HttpResponseMessage responseMessage; var userDetail = _userModel.GetUser(id); if (userDetail != null) { responseMessage = Request.CreateResponse(HttpStatusCode.OK, userDetail); } else { var json = new JSendMessage("fail", "No items found"); responseMessage = Request.CreateResponse(HttpStatusCode.NoContent, json); } return(responseMessage); }
public HttpResponseMessage GetForm(int id) { HttpResponseMessage responseMessage; JSendMessage json; FormDetailDTO formContent = formModel.GetContentForm(id); if (formContent != null) { responseMessage = Request.CreateResponse(HttpStatusCode.OK, formContent); } else { json = new JSendMessage("fail", "Poll not found"); responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json); } return(responseMessage); }
public HttpResponseMessage Result(int id) { HttpResponseMessage responseMessage; JSendMessage json; VoteResultDetailDTO voteResult = formModel.GetDetailResultForm(id); if (voteResult != null) { responseMessage = Request.CreateResponse(HttpStatusCode.OK, voteResult); } else { json = new JSendMessage("fail", "Results not found"); responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json); } return(responseMessage); }
public HttpResponseMessage Promote(int id) { HttpResponseMessage responseMessage; JSendMessage json; bool response = userModel.PromoteUser(id); if (response) { json = new JSendMessage("success", "User successfully promoted"); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "Something bad happened"); responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, json); } return(responseMessage); }
public HttpResponseMessage Post(CategoryDTO categoryDTO) { HttpResponseMessage responseMessage; JSendMessage json; bool response = categoryModel.AddCategory(categoryDTO); if (response) { json = new JSendMessage("success", "Category successfully added"); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "Something bad happened"); responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, json); } return(responseMessage); }
/// <summary> /// Primire token ce a fost trimis in mailul de activare a contului /// </summary> /// <param name="id">token</param> /// <returns>mesaj succes sau eroare</returns> public HttpResponseMessage Get(string id) { HttpResponseMessage response; JSendMessage json; bool verify = auth.VerifyMailToken(id); if (verify) { json = new JSendMessage("success", "Your account has been successfully verified"); response = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "Invalid verification link"); response = Request.CreateResponse(HttpStatusCode.Forbidden, json); } return(response); }
public HttpResponseMessage Put(UtilityDTO utilityDto) { HttpResponseMessage responseMessage; JSendMessage json; var response = _utilityModel.UpdateUtility(utilityDto); if (response) { json = new JSendMessage("success", "Utility details successfully updated"); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "Something bad happened"); responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, json); } return(responseMessage); }
public HttpResponseMessage Utilitiescar(int id) { HttpResponseMessage responseMessage; JSend json; var list = _carModel.GetAllCarUtilities(id); if (list.Count > 0) { json = new JSendData <UtilityDTO>("success", list); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "No items found"); responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json); } return(responseMessage); }
public HttpResponseMessage Delete(int id) { HttpResponseMessage responseMessage; JSendMessage json; var response = _carModel.DeleteCar(id); if (response) { json = new JSendMessage("success", "Car successfully deleted"); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "Something bad happened"); responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, json); } return(responseMessage); }
public HttpResponseMessage Post(CarDetailsDTO carDetailsDto) { HttpResponseMessage responseMessage; JSendMessage json; var response = _carModel.AddCar(carDetailsDto); if (response) { json = new JSendMessage("success", "Car successfully added"); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "Something bad happened"); responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, json); } return(responseMessage); }
public HttpResponseMessage Post([FromBody] VoteListDTO voteDTO) { HttpResponseMessage responseMessage; JSendMessage json; string token = Request.Headers.SingleOrDefault(x => x.Key == "token").Value.First(); VoteResultDTO result = formModel.Vote(voteDTO, token); if (result != null) { responseMessage = Request.CreateResponse(HttpStatusCode.OK, result); } else { json = new JSendMessage("fail", "Poll already voted"); responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, json); } return(responseMessage); }
public HttpResponseMessage UpdateUsers() { HttpResponseMessage responseMessage; JSendMessage json; var response = _contactModel.UpdateUsers(); if (response) { json = new JSendMessage("success", "Message sent successfully"); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "Something bad happened"); responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, json); } return(responseMessage); }
public HttpResponseMessage GetProducts(int productId, string lang, string currency) { HttpResponseMessage responseMessage; JSend json; var product = db.Products.Find(productId); //Random rnd = new Random(); //var product = new Products //{ // Name_RO = "Name_RO" + 1, // Name_EN = "Name_EN" + 1, // Name_IT = "Name_IT" + 1, // Price = 1, // Description_RO = "Description_RO", // Description_EN = "Description_EN", // Description_IT = "Description_IT", // ProductId = rnd.Next(1, 4) //}; if (product != null) { var productDetail = new ProductDetail { Name = ComputeName(product, lang), Price = GetCurrencyPrice(product, currency), ProductId = product.ProductId, Description = ComputeDescription(product, lang), Image = new ProductsImagesController().GetProductsImages(product.ProductId), StyleCode = product.StyleCode, LeatherType = product.LeatherType, Colour = product.Colour }; responseMessage = Request.CreateResponse(HttpStatusCode.OK, productDetail); } else { json = new JSendMessage("fail", "No items found"); responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json); } return(responseMessage); }
public HttpResponseMessage Usernames(int id) { HttpResponseMessage responseMessage; JSend json; List <UsernameDTO> list = userModel.GetAllUsernames(); if (list.Count > 0) { json = new JSendData <UsernameDTO>("success", list); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "No items found"); responseMessage = Request.CreateResponse(HttpStatusCode.NoContent, json); } return(responseMessage); }
public HttpResponseMessage Get() { HttpResponseMessage responseMessage; JSend json; List <CategoryDTO> list = categoryModel.GetAllCategories(); if (list.Count > 0) { json = new JSendData <CategoryDTO>("success", list); responseMessage = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("fail", "No items found"); responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json); } return(responseMessage); }
/// <summary> /// Primeste delatiile utilizatorului, verificare unicitate si adaugare utilizator /// </summary> /// <param name="user">delatiile utilizatorului</param> /// <returns></returns> public HttpResponseMessage Post(UserRegistrationDTO user) { var userModel = new UsersModel(); HttpResponseMessage response; JSendMessage json; var add = userModel.AddUser(user); if (add) { json = new JSendMessage("success", "Registration successful! Please, verify your mail address."); response = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("failed", "Registration failed! Please, try another username or email."); response = Request.CreateResponse(HttpStatusCode.Forbidden, json); } return(response); }
public HttpResponseMessage PostOrders(SendMessageDTO request) { HttpResponseMessage response = null; JSendMessage json; var messageAdded = users.StoreMessage(request); if (messageAdded) { json = new JSendMessage("success", "Message sent"); response = Request.CreateResponse(HttpStatusCode.OK, json); } else { json = new JSendMessage("failed", "Request failed."); response = Request.CreateResponse(HttpStatusCode.BadRequest, json); } return(response); }