static void addPromocode() { using (var context = new Context()) { Admin ad = new Admin(); Console.WriteLine("Enter UserName"); ad.UserName = Console.ReadLine(); Console.WriteLine("Enter Password"); ad.Password = Console.ReadLine(); var check = context.Admins.SingleOrDefault(t => t.UserName == ad.UserName && t.Password == ad.Password); if (check != null) { try { Promocodes dp = new Promocodes(); Console.WriteLine("Enter Promocode Name"); dp.PromocodeName = Console.ReadLine(); Console.WriteLine("Enter Promo Details"); dp.Detail = Console.ReadLine(); context.Promocodes.Add(dp); context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Incorrect UserName or Password"); } } }
static void removedPromocode() { using (var context = new Context()) { Admin ad = new Admin(); Console.WriteLine("Enter UserName"); ad.UserName = Console.ReadLine(); Console.WriteLine("Enter Password"); ad.Password = Console.ReadLine(); var check = context.Admins.SingleOrDefault(t => t.UserName == ad.UserName && t.Password == ad.Password); if (check != null) { try { Promocodes hp = new Promocodes(); Console.WriteLine("Enter Promocode Id"); hp.PromocodeId = Convert.ToInt32(Console.ReadLine()); context.Promocodes.Remove(hp); context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } else { Console.WriteLine("Incorrect UserName or Password"); } } }
public async Task <IHttpActionResult> PutPromocodes(int id, Promocodes promocodes) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != promocodes.promocodes_id) { return(BadRequest()); } db.Entry(promocodes).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PromocodesExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetPromocodes(int id) { Promocodes promocodes = await db.Promocodes.FindAsync(id); if (promocodes == null) { return(NotFound()); } return(Ok(promocodes)); }
static void getPromocodes() { using (var context = new Context()) { Promocodes hp = new Promocodes(); foreach (var item in context.Promocodes.ToList()) { Console.WriteLine($"ID {item.PromocodeId} - Name {item.PromocodeName}-Detail{item.Detail} "); } } }
public async Task <IHttpActionResult> PostPromocodes(Promocodes promocodes) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Promocodes.Add(promocodes); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = promocodes.promocodes_id }, promocodes)); }
public async Task <IHttpActionResult> DeletePromocodes(int id) { Promocodes promocodes = await db.Promocodes.FindAsync(id); if (promocodes == null) { return(NotFound()); } db.Promocodes.Remove(promocodes); await db.SaveChangesAsync(); return(Ok(promocodes)); }
public async Task <IHttpActionResult> GetCheckPromocodes(string promoname) { Promocodes promocodes = await db.Promocodes.Where(x => x.promocode_name == promoname).SingleOrDefaultAsync(); return(Ok(promocodes)); }