public IHttpActionResult PutGroceries(Guid id, Groceries groceries) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != groceries.Id) { return(BadRequest()); } db.Entry(groceries).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!GroceriesExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostGroceries(Groceries groceries) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Groceries.Add(groceries); try { db.SaveChanges(); } catch (DbUpdateException) { if (GroceriesExists(groceries.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = groceries.Id }, groceries)); }
public ActionResult Create(GrocerieViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var Grocerie = new Groceries { Id = model.Id, Product = model.Product, Stock = model.Stock, Price = model.Price, Code = model.Code, BuyLocation = model.BuyLocation, StoreName = model.StoreName }; GroceriesRepository.Add(Grocerie); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
static void Groceries() // method to call groceries and its functions { var amount = new Groceries(); // instatiating the object amount.PrintLine(); // calling the method in the object amount.Amount(); }
private void EnterMacroValues(double howMuch) { if (KalorienTrackerListe.SelectedIndex >= 0) { Groceries grocery = (Groceries)KalorienTrackerListe.SelectedItems[0]; CarbBox.Text = (double.Parse(grocery.Carbs) / 100 * howMuch).ToString(); ProteinBox.Text = (double.Parse(grocery.Protein) / 100 * howMuch).ToString(); FatBox.Text = (double.Parse(grocery.Fats) / 100 * howMuch).ToString(); } }
private void ChangeToItemBought(int itemKey) { //TODO: fix issue where Groceries UI not updating CollectionView when property flag is flipped. var selectedGrocery = Groceries.FirstOrDefault((grocery) => grocery.Key == itemKey); if (selectedGrocery != null) { selectedGrocery.Bought = !selectedGrocery.Bought; OnPropertyChanged(nameof(Groceries)); } }
public void Update(Groceries entity) { var groceries = (from g in groceriesList where g.Id == entity.Id select g).FirstOrDefault(); int index = groceriesList.IndexOf(groceries); groceriesList[index] = entity; Save(); }
public IHttpActionResult GetGroceries(Guid id) { Groceries groceries = db.Groceries.Find(id); if (groceries == null) { return(NotFound()); } return(Ok(groceries)); }
protected void Upload_1(object sender, EventArgs e) { // upload file asp.net 元件 string userID = Request.LogonUserIdentity.Name.Split('\\')[1].Trim().ToUpper(); string csvPath = Server.MapPath("~/Files/") + Path.GetFileName(FileUpload_ASP.PostedFile.FileName); //讀檔 FileUpload_ASP.SaveAs(csvPath); //temp file DataTable dt = new DataTable(); _msg = ""; dt.Columns.AddRange(new DataColumn[10] { new DataColumn("Customer_ID", typeof(string)), new DataColumn("Category", typeof(string)), new DataColumn("Part", typeof(string)), new DataColumn("Part_Id", typeof(string)), new DataColumn("Yield_Impact_Item", typeof(string)), new DataColumn("Key_Module", typeof(string)), new DataColumn("Data_Source", typeof(string)), new DataColumn("Critical_Item", typeof(string)), new DataColumn("EDA_Item", typeof(string)), new DataColumn("MAIN_ID", typeof(string)) }); string csvData = File.ReadAllText(csvPath); foreach (string row in csvData.Split('\n')) //讀csv檔 { if (!string.IsNullOrEmpty(row)) { dt.Rows.Add(); int i = 0; foreach (string cell in row.Split(',')) { dt.Rows[dt.Rows.Count - 1][i] = cell; i++; } } } Mailmaxid = DBProcess_sign.maxID(); int countID = int.Parse(Mailmaxid.Rows[0][0].ToString()) + 1; for (int i = 1; i < dt.Rows.Count; i++) //匯入資料庫,剃除表頭 { DBProcess_sign.Upload_Data(countID + i, dt.Rows[i]["Customer_ID"].ToString().Trim(), dt.Rows[i]["Category"].ToString().Trim(), dt.Rows[i]["Part"].ToString().Trim(), dt.Rows[i]["Part_Id"].ToString().Trim(), dt.Rows[i]["Yield_Impact_Item"].ToString().Trim(), dt.Rows[i]["Key_Module"].ToString().Trim(), dt.Rows[i]["Data_Source"].ToString().Trim(), dt.Rows[i]["Critical_Item"].ToString().Trim(), dt.Rows[i]["EDA_Item"].ToString().Trim(), dt.Rows[i]["MAIN_ID"].ToString().Trim(), userID, ref _msg); if (_msg != "") { X.MessageBox.Alert("提示", "Import data was error format problem ").Show(); Groceries.Delfile(csvPath); break; } } X.MessageBox.Alert("提示", "共 " + dt.Rows.Count + "筆,更新完畢。").Show(); System.Threading.Thread.Sleep(300); Groceries.Delfile(csvPath); Panel2.Reload(); Panel1.Reload(); }
public ICommandResult Handle(RegisterGroceriesCommand command) { var groceries = new Groceries(command.Name, command.Price, command.Unity, command.Category); AddNotifications(groceries.Notifications); if (IsValid()) { _groceriesRepository.Insert(groceries); } return(new RegisterGroceriesCommandResult(groceries.Id, groceries.Name, groceries.Price, groceries.Unity, groceries.Category)); }
public void ToRecipe(RecipeDetails details) { Name = details.Name; Id = details.ID; Description = details.Description; Image = details.Image; var list = ChamberOfSecrets.Proxy.dbGetContains(Id, true).ToList(); foreach (var item in list) { var grocery = new Grocery(item.Grocery.Name, Grocery.ParseEnum <Unit>(item.Grocery.Unit), Grocery.ParseEnum <Category>(item.Grocery.Category), item.Amount); Groceries.Add(grocery); } }
public IHttpActionResult DeleteGroceries(Guid id) { Groceries groceries = db.Groceries.Find(id); if (groceries == null) { return(NotFound()); } db.Groceries.Remove(groceries); db.SaveChanges(); return(Ok(groceries)); }
protected override void OnQueryChanged(string oldValue, string newValue) { base.OnQueryChanged(oldValue, newValue); if (string.IsNullOrWhiteSpace(newValue)) { ItemsSource = null; } else { ItemsSource = Groceries .Where(animal => animal.Name.ToLower().Contains(newValue.ToLower())) .ToList <Grocery>(); } }
private void InitDummyData() { Groceries.Add(new GroceryItemPresentationModel { Key = 0, Bought = false, Cat = 1, Name = "Butter", OwnerKey = 0, OwnerFName = "Chris", OwnerLName = "Dang" }); Groceries.Add(new GroceryItemPresentationModel { Key = 1, Bought = true, Cat = 2, Name = "Milk", OwnerKey = 0, OwnerFName = "Aline", OwnerLName = "Dang" }); Groceries.Add(new GroceryItemPresentationModel { Key = 2, Bought = true, Cat = 3, Name = "Eggs", OwnerKey = 0, OwnerFName = "Michelle", OwnerLName = "Dang" }); Groceries.Add(new GroceryItemPresentationModel { Key = 3, Bought = false, Cat = 1, Name = "Haha", OwnerKey = 0, OwnerFName = "Chris", OwnerLName = "Dang" }); }
public void Save(Groceries groceries) { _groceriesRepository.Save(new DataAccess.Models.Groceries { Name = groceries.Name, Items = groceries.Items.Select(item => new DataAccess.Models.GroceryItem { Name = item.Name, Quantity = item.Quantity, Calories = item.Calories, PurchaseDate = item.PurchaseDate, ExpirationDate = item.ExpirationDate, ConsumptionDate = item.ConsumptionDate }).ToList() });; }
public IActionResult Save([FromBody] Groceries groceries) { _groceriesLogic.Save(groceries); return(Ok()); }
public void Insert(Groceries entity) { groceriesList.Add(new GroceriesMap(entity.Id, entity.Name, entity.Price, entity.Unity, entity.Category)); Save(); }
static void Main(string[] args) { bool _continue = true; Console.WriteLine("This program creates a grocery list from user input and stores it to a text file at C:\\temp\\GroceryList.txt\n"); String filepath = @"C:\temp\GroceryList.txt"; while (_continue) { Console.WriteLine("\n\nEnter Grocery name.\n"); string _tempName = Console.ReadLine(); Console.WriteLine("\nEnter Grocery Quantity.\n"); double _tempQuantity = Math.Round(Convert.ToDouble(Console.ReadLine()), 0); Console.WriteLine("\nEnter Grocery Price.\n"); double _tempPrice = Convert.ToDouble(Console.ReadLine()); Groceries GroceryFinal = new Groceries(_tempName, _tempQuantity, _tempPrice); if (!File.Exists(filepath)) { StreamWriter sw = new StreamWriter(filepath); sw.WriteLine("Buy " + GroceryFinal.quantity + " " + GroceryFinal.item + " for $" + GroceryFinal.price + " each, a total cost of: " + GroceryFinal.totalcost); sw.Close(); } else if (File.Exists(filepath)) { File.AppendAllText(filepath, "\nBuy " + GroceryFinal.quantity + " " + GroceryFinal.item + " for $" + GroceryFinal.price + " each, a total cost of: " + GroceryFinal.totalcost); } StreamReader sr = new StreamReader(filepath); string textline; while ((textline = sr.ReadLine()) != null) { Console.WriteLine(textline); } sr.Close(); Console.WriteLine("\n\nPress x to exit, or any other key to enter another item.\n\n"); char _exitcheck1 = Console.ReadKey().KeyChar; if (char.ToLower(_exitcheck1) == 'x') { _continue = false; } } Console.WriteLine("\n\nPress d to delete the file or any other key to keep it in C:\\temp\\GroceryList.txt\n"); char _exitcheck2 = Console.ReadKey().KeyChar; if (char.ToLower(_exitcheck2) == 'd') { File.Delete(filepath); Console.WriteLine("\nC:\\temp\\GroceryList.txt has been deleted!\n\nPress any key to close program"); } }
public void Save(Groceries groceries) { _context.GroceryLists.Add(groceries); _context.SaveChanges(); }
public async Task <IActionResult> Save([FromBody] Groceries groceries) { await _mediator.Handle <SaveGroceriesCommand, EmptyResult>(new SaveGroceriesCommand { Groceries = groceries }); return(Ok()); }
public void AddToList(Grocery grocery) { Groceries.Add(grocery); }
public async Task Save(Groceries groceries) { _context.GroceryLists.Add(groceries); await _context.SaveChangesAsync(); }
//新增資料 protected void btnNew_DirectClick(object sender, Ext.Net.DirectEventArgs e) { string New_SYSTEM_ID = "WB"; string New_USER_NOTES = this.New_USER_NOTES.Text; string New_MAIL_ADS = this.New_MAIL_ADS.Text; string New_IS_SEND = this.New_IS_SEND.Text.ToUpper(); string New_IS_MODIFY = this.New_IS_MODIFY.Text.ToUpper(); string New_IS_CC = this.New_IS_CC.Text.ToUpper(); string New_Name = this.New_Name.Text; _msg = ""; string[] check = { New_USER_NOTES, New_MAIL_ADS, New_IS_SEND, New_IS_MODIFY, New_IS_CC, New_Name }; List <string> finishcheck = new List <string>(); //判斷格式是否正確 bool result1 = Groceries.IsNumeric(New_USER_NOTES); if (result1) { finishcheck.Add("true"); } else { finishcheck.Add("false"); } bool result2 = Groceries.IsmailValid(New_MAIL_ADS); if (result2) { finishcheck.Add("true"); } else { finishcheck.Add("false"); } bool result3 = Groceries.checkFormat(New_IS_SEND); if (result3) { finishcheck.Add("true"); } else { finishcheck.Add("false"); } bool result4 = Groceries.checkFormat(New_IS_MODIFY); if (result4) { finishcheck.Add("true"); } else { finishcheck.Add("false"); } bool result5 = Groceries.checkFormat(New_IS_CC); if (result5) { finishcheck.Add("true"); } else { finishcheck.Add("false"); } //格式正確後,才把資料匯入資料庫 bool FalseExists = finishcheck.Exists(element => element == "false"); if (FalseExists != true) { DBProcess_mail.Insert_Data(New_SYSTEM_ID, New_USER_NOTES, New_MAIL_ADS, New_IS_SEND, New_IS_MODIFY, New_IS_CC, New_Name, ref _msg); ReFlash(); X.MessageBox.Alert("提示", "已新增以下資料 USER_NOTES:" + New_USER_NOTES + " MAIL_ADS:" + New_MAIL_ADS).Show(); } else { X.MessageBox.Alert("提示", "格式有誤,請檢查格式").Show(); } }