public string Create([FromBody] ToyAdd addToy) { try { context.Toys.Single(s => s.ToyName == addToy.ToyName); return("Toy is already exist..."); } catch (Exception) { try { context.Plants.Single(s => s.PlantName == addToy.PlantName); try { context.TypeOfToys.Single(a => a.TypeName == addToy.TypeName); context.Toys.FromSqlRaw($"EXEC spToyAdd '{addToy.ToyName}',{addToy.Price},'{addToy.PlantName}','{addToy.TypeName}'"); context.SaveChanges(); return($"Toy id {context.Toys.ToList().Last().ToyId} is created..."); } catch (Exception) { return("Type is not found..."); } } catch (Exception) { return($"Plant is not found"); } } }
public string Create([FromBody] PlaceOrder AddOrder) { try { context.Database.ExecuteSqlRaw($"exec spOrders {AddOrder.customerId},'{AddOrder.Toys}','{AddOrder.Address}'"); context.SaveChanges(); Order od = context.Orders.ToList().Last(); string OrderedToys = od.Toys.Replace(' ', ',').TrimEnd(','); int OfferOrdered = od.OfferValue == 7 ? 0 : (od.OfferValue * 10); Console.WriteLine($"\tOrder Id : {od.OrderId}\n\tCustomer Id : {od.CustomerId}\n\tPlaced Toys : {OrderedToys}\n\tYour Bill : {od.Bill}"); Console.WriteLine($"\tOffer applied : {OfferOrdered}%\n\tAddress : {od.Address}"); return($"\tOrder Id : {od.OrderId}\n\tCustomer Id : {od.CustomerId}\n\tPlaced Toys : {OrderedToys}\n\tYour Bill : {od.Bill}\n\tOffer applied : {OfferOrdered}%\n\tAddress : {od.Address}"); } catch (Exception e) { return(e.Message); } }
public void Create(T entity) { context.Add(entity); context.SaveChanges(); }