コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
 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());
     }
 }
コード例 #4
0
        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();
        }
コード例 #5
0
 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();
     }
 }
コード例 #6
0
        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));
            }
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        public IHttpActionResult GetGroceries(Guid id)
        {
            Groceries groceries = db.Groceries.Find(id);

            if (groceries == null)
            {
                return(NotFound());
            }

            return(Ok(groceries));
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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));
        }
コード例 #11
0
ファイル: Recipe.cs プロジェクト: Sayrax97/SmartFridge
        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);
            }
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        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>();
            }
        }
コード例 #14
0
 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"
     });
 }
コード例 #15
0
 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()
     });;
 }
コード例 #16
0
 public IActionResult Save([FromBody] Groceries groceries)
 {
     _groceriesLogic.Save(groceries);
     return(Ok());
 }
コード例 #17
0
 public void Insert(Groceries entity)
 {
     groceriesList.Add(new GroceriesMap(entity.Id, entity.Name, entity.Price, entity.Unity, entity.Category));
     Save();
 }
コード例 #18
0
        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");
            }
        }
コード例 #19
0
 public void Save(Groceries groceries)
 {
     _context.GroceryLists.Add(groceries);
     _context.SaveChanges();
 }
コード例 #20
0
        public async Task <IActionResult> Save([FromBody] Groceries groceries)
        {
            await _mediator.Handle <SaveGroceriesCommand, EmptyResult>(new SaveGroceriesCommand { Groceries = groceries });

            return(Ok());
        }
コード例 #21
0
ファイル: Recipe.cs プロジェクト: Sayrax97/SmartFridge
 public void AddToList(Grocery grocery)
 {
     Groceries.Add(grocery);
 }
コード例 #22
0
 public async Task Save(Groceries groceries)
 {
     _context.GroceryLists.Add(groceries);
     await _context.SaveChangesAsync();
 }
コード例 #23
0
        //新增資料
        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();
            }
        }