public async Task <IHttpActionResult> process(int id) { string employeeEmail = HttpContext.Current.User.Identity.Name; int employeeid = IdFromEmail(employeeEmail); //Check Valid Cart if (cart_by_id(id) != null && cart_by_id(id).isProcessed != true) { Cart toprocess = cart_by_id(id); Sale newsale = new Sale(); newsale.CartId = id; newsale.EmployeeId = employeeid; newsale.Date = DateTime.UtcNow; newsale.TotalAmount = TotalPrice(toprocess.Games); //Process Cart toprocess.isProcessed = true; db.SaveChanges(); //Decrease Quantity if (DecreaseGameCount(toprocess.Games)) { //db.Entry(toprocess).State = EntityState.Modified; //db.SaveChanges(); //Add to Sale db.Sales.Add(newsale); db.SaveChanges(); } } return(Ok()); }
public HttpResponseMessage GetApikey(String Email, String password) { if (Email == null || password == null) { var response = Request.CreateResponse(HttpStatusCode.BadRequest); return(response); } else { bool check = new AccountController().registeredUser(Email, password); if (check == true) { var ApiKey = db.Users.FirstOrDefault(u => u.Email == Email).ApiKey; User newobj = db.Users.FirstOrDefault(u => u.Email == Email); if (ApiKey == null) { var newapikey = ""; newapikey = CustomHelpers.GetApiKey(); newobj.ApiKey = newapikey; db.SaveChanges(); } var response = Request.CreateResponse(HttpStatusCode.OK, ApiKey); return(response); } else { var responses = Request.CreateResponse(HttpStatusCode.Forbidden); return(responses); } } }
public IHttpActionResult PostGame(NewGameDTO game) { if (ModelState.IsValid) { ICollection <string> genrelist = game.Genres.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); ICollection <string> taglist = game.Tags.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); ICollection <Genre> finalgenre = new Collection <Genre>(); ICollection <Tag> finaltag = new Collection <Tag>(); Game newgame = new Game(); newgame.Name = game.Name; newgame.Price = Convert.ToDecimal(game.Price); newgame.ReleaseDate = game.ReleaseDate; newgame.InventoryCount = game.InventoryCount; foreach (string genrecheck in genrelist) { if (duplicate_genre_check(genrecheck) != 0) { finalgenre.Add(matching_genre(genrecheck)); } else { finalgenre.Add(new Genre { Name = genrecheck } ); } } foreach (string tagcheck in taglist) { if (duplicate_tag_check(tagcheck) != 0) { finaltag.Add(matching_tag(tagcheck)); } else { finaltag.Add(new Tag { Name = tagcheck } ); } } newgame.Genre = finalgenre; newgame.Tags = finaltag; db.Games.Add(newgame); db.SaveChanges(); //LOCATION IHttpActionResult response; HttpResponseMessage responseMsg = new HttpResponseMessage(HttpStatusCode.OK); responseMsg.Content = new StringContent("Game added successfully. ID : " + newgame.Id); //string uri = Url.Link("GetGamesById", new { id = newgame.Id }); //responseMsg.Headers.Location = new Uri(uri); response = ResponseMessage(responseMsg); return(response); } return(BadRequest()); }