public FoodPrice UpdateFoodPrice(FoodPrice foodPrice) { var old = _unitOfWork.DbContext.FoodPrices.First(x => x.Id == foodPrice.Id); Mapper.Map(foodPrice, old); _unitOfWork.DbContext.SaveChanges(); return(foodPrice); }
public FoodPriceDto AddFoodPrice(FoodPriceParameter foodPriceParameter, int userId) { var newFoodPrice = new FoodPrice() { FoodId = foodPriceParameter.FoodId, Price = foodPriceParameter.Price, StartDate = foodPriceParameter.StartDate ?? DateTime.Now, CreatedBy = userId, CreatedAt = DateTime.Now }; _foodPriceRepositories.AddFoodPrice(newFoodPrice); return(FoodPriceDto.ToFoodPriceDto(newFoodPrice)); }
private void FoodPriceTextBox_Validated(object sender, System.EventArgs e) { if (string.IsNullOrWhiteSpace(foodPriceTextBox.Text) || string.Compare(foodPriceTextBox.Text, "0 تومان") == 0) { FoodPrice = 0; Price = string.Empty; } else { Price = foodPriceTextBox.Text.Replace("تومان", string.Empty).Trim(); FoodPrice = decimal.Parse(Price); foodPriceTextBox.Text = $"{FoodPrice.ToString("#,0")} تومان"; Price = $"{FoodPrice.ToString("#,0")} تومان"; } }
private void FoodPriceTextBox_Leave(object sender, System.EventArgs e) { if (string.IsNullOrWhiteSpace(foodPriceTextBox.Text)) { foodPriceTextBox.Text = "مبلغ غذا"; foodPriceTextBox.ReadOnly = true; } else { foodPriceTextBox.ReadOnly = true; Price = foodPriceTextBox.Text.Replace("تومان", string.Empty).Trim(); FoodPrice = decimal.Parse(Price); foodPriceTextBox.Text = $"{FoodPrice.ToString("#,0")} تومان"; } }
private void SaveBtn_Click(object sender, RoutedEventArgs e) { var mtp = foodDate.Text.Split('/'); //System.Windows.Controls.ComboBoxItem: var tmpType = foodCombo.SelectedItem.ToString(); var foodType = tmpType.Split(new string[] { "System.Windows.Controls.ComboBoxItem:" }, StringSplitOptions.None); //foodList.Add(new Food("pizza", 12000, 3000, "morgh", "sade", "پیتزا", 23, 7, 13, 2020)); foodList.Add(new Food(foodname.Text, int.Parse(foodPrice.Text), int.Parse(FoodPrice.Text), foodInfo.Text, privateInfo.Text, foodType[1], int.Parse(foodNum.Text), int.Parse(mtp[0]), int.Parse(mtp[1]), int.Parse(mtp[2]))); //foodTemp = foodList; foodname.Clear(); foodPrice.Clear(); FoodPrice.Clear(); foodInfo.Clear(); privateInfo.Clear(); foodCombo.SelectedIndex = -1; foodNum.Clear(); foodDate.Clear(); foodPhoto.Source = null; MessageBox.Show("ثبت شد"); }
public static FoodPriceDto ToFoodPriceDto(FoodPrice model) { if (model == null) { return(null); } return(new FoodPriceDto() { Id = model.Id, FoodId = model.FoodId, Price = model.Price, StartDate = model.StartDate, IsDeleted = model.IsDeleted, CreatedBy = model.CreatedBy, CreatedAt = model.CreatedAt, UpdatedBy = model.UpdatedBy, UpdatedAt = model.UpdatedAt }); }
public FoodPrice AddFoodPrice(FoodPrice foodPrice) { _unitOfWork.DbContext.FoodPrices.Add(foodPrice); _unitOfWork.DbContext.SaveChanges(); return(foodPrice); }
private void SaveButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); string errorMessage = string.Empty; #region Validation //----- if (string.IsNullOrWhiteSpace(foodNameTextBox.Text) || string.Compare(foodNameTextBox.Text, "نام غذا") == 0) { errorMessage = "فیلد نام غذا تکمیل گردد!"; } if (string.IsNullOrWhiteSpace(foodPriceTextBox.Text) || string.Compare(foodPriceTextBox.Text, "مبلغ غذا") == 0) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "فیلد مبلغ غذا تکمیل گردد!"; } if (string.IsNullOrWhiteSpace(descriptionTextBox.Text) || string.Compare(descriptionTextBox.Text, "توضیحات") == 0) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "فیلد توضیحات تکمیل گردد!"; } if (errorMessage != string.Empty) { if (string.IsNullOrWhiteSpace(foodNameTextBox.Text) || string.Compare(foodNameTextBox.Text, "نام غذا") == 0) { foodNameTextBox.Focus(); foodNameTextBox.Clear(); } else if (string.IsNullOrWhiteSpace(foodPriceTextBox.Text) || string.Compare(foodPriceTextBox.Text, "مبلغ غذا") == 0) { foodPriceTextBox.Focus(); foodPriceTextBox.Clear(); } else if (string.IsNullOrWhiteSpace(descriptionTextBox.Text) || string.Compare(descriptionTextBox.Text, "توضیحات") == 0) { descriptionTextBox.Focus(); descriptionTextBox.Clear(); } ErrorMessage(errorMessage); return; } if (string.IsNullOrEmpty(FoodImage)) { System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog { Filter = "JPEP (*.jpg)|*.jpg|" + "PNG (*.png)|*.png|" + "BMP (*.bmp)|*.bmp", Title = "Load user picture ", }; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FoodImage = openFileDialog.FileName; foodImagePicturBox.Image = System.Drawing.Image.FromFile(FoodImage); } return; } //----- #endregion /Validation errorMessageLabel.Visible = false; errorMessage = string.Empty; System.Windows.Forms.DialogResult dialogResult; dialogResult = Mbb.Windows.Forms.MessageBox.QuestionMessage (text: $"{FoodName} ثبت گردد؟", captiopn: "ثبت غذا", buttons: System.Windows.Forms.MessageBoxButtons.YesNo, defaultButton: System.Windows.Forms.MessageBoxDefaultButton.Button2, icon: System.Windows.Forms.MessageBoxIcon.Question, options: System.Windows.Forms.MessageBoxOptions.RightAlign | System.Windows.Forms.MessageBoxOptions.RtlReading); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { Models.Food food = dataBaseContext.Foods .Where(current => string.Compare(current.FoodName, FoodName, false) == 0) .FirstOrDefault(); if (food != null) { errorMessage = $"{FoodName} در سیستم موجود است!"; ErrorMessage(errorMessage); foodNameTextBox.Focus(); foodNameTextBox.SelectAll(); return; } else { RegisterDate = Infrastructure.Utility.PersianCalendar(System.DateTime.Now); RegisterTime = Infrastructure.Utility.ShowTime(); food = new Models.Food { FoodName = FoodName, FoodPrice = $"{FoodPrice.ToString("#,0")} تومان", Description = Description, FoodImage = System.IO.File.ReadAllBytes(FoodImage), RegisterTime = RegisterDate + " " + RegisterTime, UpdateTime = UpdateTime, NumberUpdate = int.Parse(NumberUpdate), }; dataBaseContext.Foods.Add(food); dataBaseContext.SaveChanges(); //-----جهت بارگذاری اطلاعات غذا در جدول داده if (Resturant.MainForm.MenuListForm != null) { Resturant.MainForm.MenuListForm.FoodLoader(); } string message = $"{FoodName} ثبت گردید."; Infrastructure.Utility.WindowsNotification (message: message, caption: Infrastructure.PopupNotificationForm.Caption.موفقیت, picture: FoodImage); AllClear(); } } else { return; } } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }