public DiscountResponse Create(DiscountViewModel discount)
        {
            DiscountResponse response = new DiscountResponse();

            try
            {
                response = WpfApiHandler.SendToApi <DiscountViewModel, DiscountResponse>(discount, "Create");
            }
            catch (Exception ex)
            {
                response.Discount = new DiscountViewModel();
                response.Success  = false;
                response.Message  = ex.Message;
            }

            return(response);
        }
Exemplo n.º 2
0
        public DiscountResponse GetAllDiscounts()
        {
            DiscountResponse discountResponse = new DiscountResponse();

            try
            {
                discountResponse.discountList = repository.GetAllDiscounts().ToList();
                discountResponse.Success      = true;
            }
            catch (Exception ex)
            {
                discountResponse.Success    = false;
                discountResponse.Message    = ex.Message;
                discountResponse.StackTrace = ex.StackTrace;
            }

            return(discountResponse);
        }
        public DiscountResponse Delete(Guid identifier)
        {
            DiscountResponse response = new DiscountResponse();

            try
            {
                DiscountViewModel discount = new DiscountViewModel();
                discount.Identifier = identifier;
                response            = WpfApiHandler.SendToApi <DiscountViewModel, DiscountResponse>(discount, "Delete");
            }
            catch (Exception ex)
            {
                response.Discount = new DiscountViewModel();
                response.Success  = false;
                response.Message  = ex.Message;
            }

            return(response);
        }
Exemplo n.º 4
0
        public DiscountResponse Delete(Guid identifier)
        {
            DiscountResponse response = new DiscountResponse();

            try
            {
                Discount deletedDiscount = unitOfWork.GetDiscountRepository().Delete(identifier);

                unitOfWork.Save();

                response.Discount = deletedDiscount.ConvertToDiscountViewModel();
                response.Success  = true;
            }
            catch (Exception ex)
            {
                response.Discount = new DiscountViewModel();
                response.Success  = false;
                response.Message  = ex.Message;
            }

            return(response);
        }
Exemplo n.º 5
0
        public DiscountResponse Create(DiscountViewModel re)
        {
            DiscountResponse response = new DiscountResponse();

            try
            {
                Discount addedDiscount = unitOfWork.GetDiscountRepository().Create(re.ConvertToDiscount());

                unitOfWork.Save();

                response.Discount = addedDiscount.ConvertToDiscountViewModel();
                response.Success  = true;
            }
            catch (Exception ex)
            {
                response.Discount = new DiscountViewModel();
                response.Success  = false;
                response.Message  = ex.Message;
            }

            return(response);
        }
Exemplo n.º 6
0
        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            Thread th = new Thread(() =>
            {
                DiscountDataLoading = true;

                if (CurrentDiscount == null)
                {
                    MainWindow.WarningMessage = ((string)Application.Current.FindResource("Morate_odabrati_stavku_za_brisanjeUzvičnik"));
                    DiscountDataLoading       = false;
                    return;
                }

                DiscountResponse response = DiscountService.Delete(CurrentDiscount.Identifier);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_brisanja_sa_serveraUzvičnik"));
                    DiscountDataLoading     = false;
                    return;
                }

                response = new DiscountSQLiteRepository().Delete(CurrentDiscount.Identifier);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_lokalnog_brisanjaUzvičnik"));
                    DiscountDataLoading     = false;
                    return;
                }

                MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_obrisaniUzvičnik"));

                DisplayDiscountData();

                DiscountDataLoading = false;
            });

            th.IsBackground = true;
            th.Start();
        }
        public DiscountResponse GetDiscount(Guid identifier)
        {
            DiscountResponse  response = new DiscountResponse();
            DiscountViewModel discount = null;

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM Discounts " +
                        "WHERE Identifier = @Identifier;", db);
                    selectCommand.Parameters.AddWithValue("@Identifier", identifier);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        DiscountViewModel dbEntry = Read(query);
                        discount = dbEntry;
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    response.Discount       = new DiscountViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success  = true;
            response.Discount = discount;
            return(response);
        }
        public JsonResult Delete([FromBody] DiscountViewModel discount)
        {
            DiscountResponse response = new DiscountResponse();

            try
            {
                response = this.discountService.Delete(discount.Identifier);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                Console.WriteLine(ex.Message);
            }

            JsonResult result = Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting            = Newtonsoft.Json.Formatting.Indented,
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize
            });

            return(result);
        }
 public void ComputeDiscountOnCart(DiscountRule rule, DiscountRequest discountRequest, DiscountResponse discountResponse)
 {
     // Do Nothing
 }
 public void ComputeDiscountOnItem(DiscountRule rule, DiscountRequest discountRequest, DiscountResponse discountResponse, DiscountRequestItem item)
 {
     item.TotalDiscount += rule.Value;
 }
Exemplo n.º 11
0
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (String.IsNullOrEmpty(CurrentDiscount.Name))
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Naziv"));
                return;
            }

            #endregion

            Thread th = new Thread(() =>
            {
                SubmitButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke"));
                SubmitButtonEnabled = false;

                CurrentDiscount.IsSynced = false;
                CurrentDiscount.Company  = new CompanyViewModel()
                {
                    Id = MainWindow.CurrentCompanyId
                };
                CurrentDiscount.CreatedBy = new UserViewModel()
                {
                    Id = MainWindow.CurrentUserId
                };

                DiscountResponse response = DiscountService.Create(CurrentDiscount);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_čuvanja_na_serveruUzvičnik"));
                    SubmitButtonContent     = ((string)Application.Current.FindResource("Proknjiži"));
                    SubmitButtonEnabled     = true;
                }

                if (response.Success)
                {
                    MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik"));
                    SubmitButtonContent       = ((string)Application.Current.FindResource("Proknjiži"));
                    SubmitButtonEnabled       = true;

                    DiscountCreatedUpdated();

                    if (IsCreateProcess)
                    {
                        CurrentDiscount            = new DiscountViewModel();
                        CurrentDiscount.Identifier = Guid.NewGuid();

                        Application.Current.Dispatcher.BeginInvoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(() =>
                        {
                            txtAmount.Focus();
                        })
                            );
                    }
                    else
                    {
                        Application.Current.Dispatcher.BeginInvoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(() =>
                        {
                            if (IsPopup)
                            {
                                FlyoutHelper.CloseFlyoutPopup(this);
                            }
                            else
                            {
                                FlyoutHelper.CloseFlyout(this);
                            }
                        })
                            );
                    }
                }
            });
            th.IsBackground = true;
            th.Start();
        }
Exemplo n.º 12
0
 public void ComputeDiscountOnCart(DiscountRule rule, DiscountRequest discountRequest, DiscountResponse discountResponse)
 {
     discountRequest.TotalDiscount += rule.Value;
 }
Exemplo n.º 13
0
 public void ComputeDiscountOnItem(DiscountRule rule, DiscountRequest discountRequest, DiscountResponse discountResponse, DiscountRequestItem item)
 {
     // Do nothing
 }