예제 #1
0
        public async Task <IActionResult> Promotion(PromotionsViewModel promotions)
        {
            promotions.Promotions = HttpContext.Session.GetSession <List <PromotionViewModel> >("Promotions");
            if (!ModelState.IsValid)
            {
                return(View(promotions));
            }

            var promotion = _mapper.Map <PromotionViewModel, Promotion>(promotions.PromotionInContext);

            if (promotions.IsEdit)
            {
                // Update Promotion
                await _promotionOperations.UpdatePromotionAsync(promotions.PromotionInContext.RowKey, promotion);
            }
            else
            {
                // Insert Promotion
                promotion.RowKey = Guid.NewGuid().ToString();
                await _promotionOperations.CreatePromotionAsync(promotion);

                if (!promotion.IsDeleted)
                {
                    // Broadcast the message to all clients asscoaited with new promotion
                    _signalRConnectionManager.GetHubContext <ServiceMessagesHub>()
                    .Clients
                    .All
                    .publishPromotion(promotion);
                }
            }

            return(RedirectToAction("Promotion"));
        }
예제 #2
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                viewM = this.Main.DataContext as PromotionsViewModel;
                viewM.SelectedData = new Promotions();
                InsertData view = new InsertData("AJOUT", viewM.SelectedData, viewM);
                view.ShowDialog();

                if (view.Msg == "OK")
                {
                    MessageBox.Show("Opération effectuée avec succès", "Promotions", MessageBoxButton.OK, MessageBoxImage.Information);
                    viewM.Refresh();
                }
                else if (view.Msg == "Error")
                {
                    MessageBox.Show("   Echec Opération    ", "Promotions ", MessageBoxButton.OK, MessageBoxImage.Warning);
                    viewM.Refresh();
                }
                else
                {
                    viewM.Refresh();
                }
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Promotions", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        public ActionResult PromotionDetails(int?id)
        {
            if (id == null)
            {
                throw new Exception("Invalid URL - promotion's id can not be null");
            }

            PromotionsViewModel viewModel = this.promotionService.GetDetails(id);

            if (viewModel == null)
            {
                throw new Exception($"Invalid URL - there is no promotion with id {id}");
            }

            if (viewModel.AreThereBooks == false)
            {
                this.TempData["Info"] = "No books.";
            }

            if (viewModel.EndDate < DateTime.Now)
            {
                this.TempData["Info"] = "Expired promotion";
                return(RedirectToAction("Index", "Home"));
            }

            return(View(viewModel));
        }
예제 #4
0
        public async Task <IActionResult> Put(string id, [FromBody] PromotionsViewModel item)
        {
            await _documentClient.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, id),
                                                       item);

            return(Ok());
        }
예제 #5
0
        private void btnAnnuler_Click(object sender, RoutedEventArgs e)
        {
            PromotionsViewModel vehi = this.DataContext as PromotionsViewModel;

            vehi.SelectedData = null;

            this.Close();
        }
예제 #6
0
        public PromotionsViewModel GetDetails(int?id)
        {
            Promotion promotion = this.Context.Promotions.Find(id);

            if (promotion == null)
            {
                return(null);
            }

            PromotionsViewModel promotionsViewModel = Mapper.Map <Promotion, PromotionsViewModel>(promotion);

            promotionsViewModel.AreThereBooks = CheckIfThereAreBooks(promotion);
            return(promotionsViewModel);
        }
예제 #7
0
        //Evenement double clic du RadGridview
        void OnGridMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement originalSender = e.OriginalSource as FrameworkElement;

            if (originalSender != null)
            {
                //var cell = originalSender.ParentOfType<GridViewCell>();
                //if (cell != null)
                //{
                //    MessageBox.Show("The double-clicked cell is " + cell.Value);
                //}

                var row = originalSender.ParentOfType <GridViewRow>();
                if (row != null)
                {
                    try
                    {
                        if (GlobalData.VerificationDroit("CanEditPromotions"))
                        {
                            viewM = this.Main.DataContext as PromotionsViewModel;

                            InsertData view = new InsertData("MOD", viewM.SelectedData, viewM);
                            view.ShowDialog();

                            if (view.Msg == "OK")
                            {
                                MessageBox.Show("Opération effectuée avec succès", "Promotions", MessageBoxButton.OK, MessageBoxImage.Information);
                                viewM.Refresh();
                            }
                            else if (view.Msg == "Error")
                            {
                                MessageBox.Show("    Echec Opération    ", "Promotions", MessageBoxButton.OK, MessageBoxImage.Warning);
                                viewM.Refresh();
                            }
                            else
                            {
                                viewM.Refresh();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "Veuillez fermer le formulaire puis recommencer.", "CATEGORIE", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
            }
        }
예제 #8
0
        public InsertData(string etat, Promotions ele, PromotionsViewModel view)
        {
            InitializeComponent();

            this.DataContext = viewVM = view;

            Etat = etat;

            if (etat == "AJOUT")
            {
                this.Title = "Enregistrement d'un Quartier";
            }
            else
            {
                this.Title = "Modification d'un Quartier";
            }
        }
예제 #9
0
        private void btnValider_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PromotionsViewModel vm  = this.DataContext as PromotionsViewModel;
                Promotions          ent = vm.SelectedData;

                if (Etat == "AJOUT")
                {
                    try
                    {
                        ent.Etat    = "ACTIF";
                        ent.idHotel = 1;
                        viewVM.model.Promotions.Add(ent);
                        viewVM.model.SaveChanges();
                        Msg = "OK";
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        Msg      = "Error";
                        ErrorMsg = ex.Message;
                    }
                }
                else
                {
                    try
                    {
                        viewVM.model.SaveChanges();

                        Msg = "OK";
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        Msg      = "Error";
                        ErrorMsg = ex.Message;
                    }
                }
            }
            catch (Exception)
            {
            }
        }
예제 #10
0
        public ActionResult AddPromoCode()
        {
            var customer = HttpContext.GetCustomer();
            var cart     = CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID());

            var promotions = !cart.PromotionsEnabled
                                ? Enumerable.Empty <PromotionViewModel>()
                                : cart
                             .DiscountResults
                             .Where(discountResult => discountResult != null)
                             .Select(discountResult => new PromotionViewModel(
                                         code: discountResult.Promotion.Code,
                                         description: discountResult.Promotion.Description));

            var model = new PromotionsViewModel(
                enteredPromoCode: string.Empty,
                promotions: promotions);

            return(PartialView(ViewNames.AddPromoCodePartial, model));
        }
        public ActionResult Create(PromotionsViewModel Promotions)
        {
            if (ModelState.IsValid)
            {
                Promotions promotion      = new Promotions();
                var        claimsIdentity = User.Identity as ClaimsIdentity;

                UserInfo userInfo = new UserInfo(db);

                Mapper.Map(Promotions, promotion);

                Companies company = userInfo.getLoggedCompanyId(claimsIdentity);
                promotion.Companies = company;
                db.Promotions.Add(promotion);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(Promotions));
        }
        // GET: Admin/Promotions/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                throw new Exception("Invalid URL - promotion's id can not be null");
            }

            PromotionsViewModel viewModel = this.promotionService.GetDetails(id);

            if (viewModel == null)
            {
                throw new Exception($"Invalid URL - there is no promotion with id {id}");
            }

            if (viewModel.AreThereBooks == false)
            {
                this.TempData["Info"] = "No books.";
            }

            return(View(viewModel));
        }
예제 #13
0
        public ActionResult AddPromoCode(PromotionsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            var promoCode = model.EnteredCode.ToLower();
            var customer  = HttpContext.GetCustomer();
            var cart      = CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID());

            var validationResults         = PromotionManager.ValidatePromotion(promoCode, PromotionManager.CreateRuleContext(cart));
            var validationFailureMessages = validationResults
                                            .Where(validationResult => !validationResult.IsValid)
                                            .SelectMany(validationResult => validationResult.Reasons)
                                            .Select(reason => new
            {
                message = AppLogic.GetString(reason.MessageKey),
                context = reason.ContextItems,
            })
                                            .Select(o => o.context == null
                                        ? o.message
                                        : o.context.Aggregate(
                                                        o.message,
                                                        (message, item) => message.Replace(string.Format("{{{0}}}", item.Key), item.Value.ToString())));

            if (validationFailureMessages.Any())
            {
                foreach (var failureMessage in validationFailureMessages)
                {
                    ModelState.AddModelError("EnteredCode", failureMessage);
                }

                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            PromotionManager.AssignPromotion(customer.CustomerID, promoCode);

            return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
        }
예제 #14
0
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid.SelectedItem != null)
            {
                try
                {
                    //if (GlobalData.VerificationDroit("CanAddPromotions"))
                    //{
                    viewM = this.Main.DataContext as PromotionsViewModel;
                    InsertData view = new InsertData("MOD", viewM.SelectedData, viewM);
                    view.ShowDialog();

                    if (view.Msg == "OK")
                    {
                        MessageBox.Show("Opération effectuée avec succès", "Promotions", MessageBoxButton.OK, MessageBoxImage.Information);
                        viewM.Refresh();
                    }
                    else if (view.Msg == "Error")
                    {
                        MessageBox.Show("    Echec Opération    ", "Promotions", MessageBoxButton.OK, MessageBoxImage.Warning);
                        viewM.Refresh();
                    }
                    else
                    {
                        viewM.Refresh();
                    }

                    //}
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Promotions", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            else
            {
                MessageBox.Show("Aucune ligne selectionnée dans la liste", "Promotions", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
예제 #15
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            //if (GlobalData.VerificationDroit("CanAddPromotions"))
            //{

            var result = MessageBox.Show("Voulez vous vraiment supprimer ?", "Message", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                if (dataGrid.SelectedItem != null)
                {
                    try
                    {
                        viewM = this.Main.DataContext as PromotionsViewModel;
                        Promotions ent = dataGrid.SelectedItem as Promotions;
                        ent.Etat = "SUPPRIMER";

                        viewM.model.SaveChanges();

                        viewM.Refresh();

                        MessageBox.Show("Opération effectuée avec succès", "Promotions", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Promotions", MessageBoxButton.OK, MessageBoxImage.Warning);
                        viewM.Refresh();
                    }
                }
                else
                {
                    MessageBox.Show("Aucune ligne selectionnée dans la liste", "Promotions", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            //}
        }
예제 #16
0
        public async Task <IActionResult> Post([FromBody] PromotionsViewModel item)
        {
            var response = await _documentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseId, collectionId), item);

            return(Ok());
        }
예제 #17
0
 public Promotions()
 {
     InitializeComponent();
     _viewModel  = new PromotionsViewModel();
     DataContext = _viewModel;
 }
        public ActionResult Index()
        {
            var model = new PromotionsViewModel(ControllersEnum.Home, promotionsDb);

            return(View(model));
        }
예제 #19
0
 private void btnRefresh_Click(object sender, RoutedEventArgs e)
 {
     viewM = this.Main.DataContext as PromotionsViewModel;
     viewM.Refresh();
 }