Пример #1
0
        /// <summary>
        /// Update the Mode property with the temporary changes, if the changes are valid.
        /// </summary>
        /// <returns>False if the changes were invalid. True if the save succeeded.</returns>
        public bool SaveChanges()
        {
            IsEditMode = false;
            RaisePropertyChanged(nameof(IsEditMode));

            // If the text box was empty, default to zero
            EditModeHours   = EditModeHours != null && EditModeHours.Length > 0 ? EditModeHours : "0";
            EditModeMinutes = EditModeMinutes != null && EditModeMinutes.Length > 0 ? EditModeMinutes : "0";
            EditModeSeconds = EditModeSeconds != null && EditModeSeconds.Length > 0 ? EditModeSeconds : "0";

            if (EditModeName == null ||
                EditModeName.Length == 0 ||
                !int.TryParse(EditModeHours, out int hours) ||
                !int.TryParse(EditModeMinutes, out int minutes) ||
                !int.TryParse(EditModeSeconds, out int seconds) ||
                (hours == 0 && minutes == 0 && seconds == 0))
            {
                // Invalid mode, fail silently.
                return(false);
            }

            Guid modeId = Mode?.Id ?? Guid.NewGuid();

            Mode = new ModeModel()
            {
                ModeName   = EditModeName,
                TimeInMode = new TimeSpan(hours, minutes, seconds),
                Id         = modeId
            };

            RaisePropertyChanged(nameof(ModeString));
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Clears the queue of currently scheduled notifications and schedules all notifications that should happen in the next 30 min.
        /// 30 min is chosen because our background task is guarenteed to run every 30 min (smallest possible interval).
        /// Each time the background task runs, it will call this function and set all notifications that should appear before the next time the task is able to run.
        /// </summary>
        public void ScheduleNotifications()
        {
            if (!HasMultipleModes)
            {
                // Don't try to schedule notitfications if the user has not set any modes
                return;
            }

            List <string> removedNotifications = new List <string>();
            List <string> addedNotifications   = new List <string>();

            // First, clear the scheduled notification queue
            IReadOnlyList <ScheduledToastNotification> scheduledNotifications = _toastNotifier.GetScheduledToastNotifications();

            foreach (ScheduledToastNotification notification in scheduledNotifications)
            {
                removedNotifications.Add(notification.DeliveryTime.ToString());
                _toastNotifier.RemoveFromSchedule(notification);
            }

            // Clear any of our existing notifications from the user's action center
            // TODO: leaving this in for now to test. Want to make sure that past notifications fire properly
            //ToastNotificationManager.History.Clear();

            if (State == TimerState.Running)
            {
                // Schedule all notifications that will appear in the next 30 min
                DateTimeOffset now                  = DateTimeOffset.Now;
                TimeSpan       thirtyMin            = TimeSpan.FromMinutes(30);
                ModeModel      modeToNotifyEnd      = CurrentMode;
                DateTimeOffset nextNotificationTime = now + GetTimeRemainingInCurrentMode();

                while (nextNotificationTime - now < thirtyMin)
                {
                    ModeModel nextMode = getNextMode(modeToNotifyEnd);

                    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01);
                    IXmlNode    textNode = toastXml.GetElementsByTagName("text")[0];
                    textNode.AppendChild(toastXml.CreateTextNode($"Time to {nextMode}! ({nextNotificationTime.ToString("t")})"));

                    ScheduledToastNotification notification = new ScheduledToastNotification(toastXml, nextNotificationTime);
                    _toastNotifier.AddToSchedule(notification);
                    addedNotifications.Add(notification.DeliveryTime.ToString());

                    modeToNotifyEnd = nextMode;

                    TimeSpan timeForMode = modeToNotifyEnd.TimeInMode;
                    nextNotificationTime = nextNotificationTime + timeForMode;
                }
            }

            _lastDebugInfo = new DebugInfo()
            {
                LastRunTime                   = DateTime.Now,
                NotificationsScheduled        = addedNotifications.ToArray(),
                ScheduledNotificationsRemoved = removedNotifications.ToArray()
            };
        }
Пример #3
0
        static public DialogResult SelectMode(string title, string promptText, ModeModel mode, ref ModeModel modeRef, List <ModeModel> modeList)
        {
            Form       form         = new Form();
            Label      label        = new Label();
            ComboBox   comboBox     = new ComboBox();
            Button     buttonOk     = new Button();
            Button     buttonCancel = new Button();
            PictureBox pictureBox   = new PictureBox();

            form.Text  = title;
            label.Text = promptText;

            comboBox.DataSource    = modeList;
            comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            form.Shown            += (s, e) =>
            {
                if (mode != null)
                {
                    ModeModel selectedItem = modeList.Find(m => m.value.Equals(mode.value));
                    if (selectedItem != null)
                    {
                        comboBox.SelectedItem = selectedItem;
                    }
                }
            };

            buttonOk.Text             = "OK";
            buttonCancel.Text         = "Cancel";
            buttonOk.DialogResult     = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            label.SetBounds(9, 20, 372, 13);
            comboBox.SetBounds(12, 36, 372, 20);
            buttonOk.SetBounds(228, 72, 75, 23);
            buttonCancel.SetBounds(309, 72, 75, 23);

            label.AutoSize      = true;
            comboBox.Anchor     = comboBox.Anchor | AnchorStyles.Right;
            buttonOk.Anchor     = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new Size(396, 107);
            form.Controls.AddRange(new Control[] { label, comboBox, buttonOk, buttonCancel });
            form.ClientSize      = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.None;
            form.StartPosition   = FormStartPosition.CenterScreen;
            form.MinimizeBox     = false;
            form.MaximizeBox     = false;
            form.AcceptButton    = buttonOk;
            form.CancelButton    = buttonCancel;

            DialogResult dialogResult = form.ShowDialog();

            modeRef = (ModeModel)comboBox.SelectedValue;
            return(dialogResult);
        }
Пример #4
0
        private ModeModel getNextMode(ModeModel currentMode)
        {
            int currentModeIndex = Modes.FindIndex(mode => mode.Id == currentMode.Id);

            Debug.Assert(currentModeIndex >= 0 || !HasMultipleModes);

            return(HasMultipleModes ?
                   Modes[(currentModeIndex + 1) % Modes.Count] :
                   null);
        }
Пример #5
0
        public IViewComponentResult Invoke(string modeName = "settings-advanced-mode")
        {
            var model = new ModeModel
            {
                ModeName = modeName,
                Enabled  = _workContext.CurrentCustomer.GetAttribute <bool>(modeName)
            };

            return(View(model));
        }
Пример #6
0
        public virtual ActionResult Mode(string modeName = "settings-advanced-mode")
        {
            var model = new ModeModel
            {
                ModeName = modeName,
                Enabled  = _workContext.CurrentCustomer.GetAttribute <bool>(modeName)
            };

            return(PartialView(model));
        }
Пример #7
0
        /// <summary>
        /// Cargar datos del comboBox de modos en interfaz.
        /// </summary>
        protected ModeModel loadDataCellMode(ModeModel mode)
        {
            ModeModel modeRef = null;

            if (Dialog.SelectMode("Modos disponibles", "Seleccione el modo:", mode, ref modeRef, mainController.modeList) == DialogResult.OK)
            {
                mode = modeRef;
            }
            return(mode);
        }
Пример #8
0
        public void Initialize(SaveStateModel savedState)
        {
            Modes = savedState?.Modes ?? new List <ModeModel>();

            if (!HasMultipleModes)
            {
                return;
            }

            DateTime now = DateTime.Now;

            State       = savedState.TimerState;
            CurrentMode = savedState.CurrentMode;
            _timeRemainingInCurrentMode = savedState.TimeRemainingInCurrentMode;

            if (State == TimerState.Running)
            {
                // Use the saved state as a starting point and then figure out what mode we should currently be in based on the
                // elapsed time.
                ModeModel mode = savedState.CurrentMode;

                DateTime modeStartTime = savedState.CurrentModeStartTime;
                DateTime modeEndTime   = modeStartTime + mode.TimeInMode;

                bool modeChangedSinceLastRun = false;
                while (modeEndTime < now)
                {
                    modeStartTime           = modeEndTime;
                    mode                    = getNextMode(mode);
                    modeEndTime             = modeStartTime + mode.TimeInMode;
                    modeChangedSinceLastRun = true;
                }

                _currentModeStart = modeStartTime;
                CurrentMode       = mode;

                if (modeChangedSinceLastRun && now - savedState.LastRunDebugInfo.LastRunTime > TimeSpan.FromMinutes(30))
                {
                    // If we have not run in the past 30 min, then the user's computer was off.
                    // In this case figure out if the mode has changed at all since the last notification and if so,
                    // we will force a notification immediately to notify the user which mode they are in.

                    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01);
                    IXmlNode    textNode = toastXml.GetElementsByTagName("text")[0];
                    textNode.AppendChild(toastXml.CreateTextNode($"Time to {CurrentMode}! ({modeStartTime.ToString("t")})"));

                    ToastNotification notification = new ToastNotification(toastXml);
                    _toastNotifier.Show(notification);
                }
            }

            // This will finish initializing the _currentModeStart and the _timeRemainingInCurrentMode variables.
            GetTimeRemainingInCurrentMode();
        }
Пример #9
0
        public async Task <ActionResult> ModeDetail(int id)
        {
            ModeModel model = await dal.GetListModeWithNoInclude().FirstOrDefaultAsync(e => e.id == id);

            model.Coordinate.Lat = model.Coordinate.Lat.Replace(",", ".");
            model.Coordinate.Lon = model.Coordinate.Lon.Replace(",", ".");
            model.ViewNumber++;
            dal.UpdateNumberView(model);

            return(View(model));
        }
Пример #10
0
 public ActionResult Create(ModeModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.MODE_ID == 0)
         {
             ModeModel.insertMode(model);
             ModelState.Clear();
             return(Json("Save mode successfully.", JsonRequestBehavior.AllowGet));
         }
         else
         {
             ModeModel.updateMode(model);
             ModelState.Clear();
             return(Json("Update mode successfully.", JsonRequestBehavior.AllowGet));
         }
     }
     else
     {
         return(Json("Please fill all fields.", JsonRequestBehavior.AllowGet));
     }
 }
Пример #11
0
        public void UpdateModes(List <ModeModel> modes)
        {
            bool wasPreviouslyInitialized = HasMultipleModes;

            Modes = modes;
            ModeModel newCurrentMode = Modes.FirstOrDefault(mode => (mode.Id == CurrentMode?.Id));

            if ((!wasPreviouslyInitialized || newCurrentMode == null) && HasMultipleModes)
            {
                // Reset the mode if this we went from an uninitialized to an initialized state or if the current mode has been deleted
                CurrentMode                 = Modes[0];
                _currentModeStart           = DateTime.Now;
                _timeRemainingInCurrentMode = CurrentMode.TimeInMode;
                GetTimeRemainingInCurrentMode();
            }
            else if (newCurrentMode != null)
            {
                // Update the current mode to get any edits that might have been made to it.
                CurrentMode = newCurrentMode;
            }

            // Update the notification queue since things have been changed
            ScheduleNotifications();
        }
Пример #12
0
 public ModeVM(ModeModel mode)
 {
     Mode       = mode;
     IsEditMode = false;
 }
Пример #13
0
        public async Task <ActionResult> AddMode(ModeViewModel mode, ImageModelView userImage)
        {
            bool isLookAuKwat = false;
            bool isParticuler = false;
            bool isPromotion  = false;

            if (User.IsInRole(MyRoleConstant.RoleAdmin) || (User.IsInRole(MyRoleConstant.Role_SuperAgent)))
            {
                isLookAuKwat = true;
                isPromotion  = true;
            }
            else
            {
                isParticuler = true;
            }

            if (mode.Stock == 0)
            {
                mode.Stock = 1;
            }


            List <string> TypeList = new List <string>();

            TypeList.Add(mode.TypeModeAccesorieLugages);
            TypeList.Add(mode.TypeModeBabyClothes);
            TypeList.Add(mode.TypeModeBabyEquipment);
            TypeList.Add(mode.TypeModeClothes);
            TypeList.Add(mode.TypeModeShoes);
            TypeList.Add(mode.TypeModeWatchJewelry);



            string type = null;

            foreach (var brand in TypeList)
            {
                if (brand != null)
                {
                    type = brand;
                }
            }
            List <string> BrandList = new List <string>();

            BrandList.Add(mode.BrandModeClothes);
            BrandList.Add(mode.BrandModeShoes);


            string Brand = null;

            foreach (var modell in BrandList)
            {
                if (modell != null)
                {
                    Brand = modell;
                }
            }

            List <string> SizeList = new List <string>();

            SizeList.Add(mode.SizeModeClothes);
            SizeList.Add(mode.SizeModeShoes);


            string Size = null;

            foreach (var modell in SizeList)
            {
                if (modell != null)
                {
                    Size = modell;
                }
            }
            if (mode.SearchOrAskMode == "Je vends")
            {
                mode.SearchOrAskMode = "J'offre";
            }
            ModeModel model = new ModeModel()
            {
                id             = mode.id,
                Title          = mode.TitleMode,
                Description    = mode.DescriptionMode,
                RubriqueMode   = mode.RubriqueMode,
                Town           = mode.TownMode,
                Price          = mode.PriceMode,
                Street         = mode.StreetMode,
                BrandMode      = Brand,
                TypeMode       = type,
                SizeMode       = Size,
                StateMode      = mode.StateMode,
                UniversMode    = mode.UniversMode,
                ColorMode      = mode.ColorMode,
                DateAdd        = DateTime.Now,
                SearchOrAskJob = mode.SearchOrAskMode,
                IsActive       = true,
                IsLookaukwat   = isLookAuKwat,
                IsParticulier  = isParticuler,
                IsPromotion    = isPromotion,
                Provider_Id    = mode.Provider_Id,
                Stock_Initial  = mode.Stock,
                Stock          = mode.Stock,
                ProductCountry = mode.ProductCountry,
            };
            string success = null;

            if (ModelState.IsValid)
            {
                using (var httpClient = new HttpClient())
                {
                    string          userId = User.Identity.GetUserId();
                    ApplicationUser user   = dal.GetUserByStrId(userId);

                    var fullAddress = $"{model.Street /*+ ","+ model.Town + ",Cameroun"*/}";
                    var response    = await httpClient.GetAsync("https://api.opencagedata.com/geocode/v1/json?q=" + fullAddress + "&key=a196040df44a4a41a471173aed07635c");

                    if (response.IsSuccessStatusCode)
                    {
                        var jsonn = await response.Content.ReadAsStringAsync();

                        var joo  = JObject.Parse(jsonn);
                        var latt = (string)joo["results"][0]["geometry"]["lat"];
                        var lonn = (string)joo["results"][0]["geometry"]["lng"];

                        List <ImageProcductModel> images = ImageAdd(userImage);

                        model.Images   = images;
                        model.User     = user;
                        model.Category = new CategoryModel {
                            CategoryName = "Mode"
                        };
                        dal.AddMode(model, latt, lonn);
                        //check if email or phone is confirm and update date of publish announce for agent pay
                        if ((user.EmailConfirmed == true || user.PhoneNumberConfirmed == true) && user.Date_First_Publish == null)
                        {
                            dal.Update_Date_First_Publish(user);
                        }

                        // success = "Annonce ajoutée avec succès dans la liste !";
                        //return RedirectToAction("UserProfile", "Home", new { message = success });
                        // return RedirectToAction("GetListProductByUser_PartialView", "User");
                        return(RedirectToAction("AddImage", "Job", new { id = model.id }));
                    }
                }
            }
            success = "Désolé une erreur s'est produite!";
            return(RedirectToAction("UserProfile", "Home", new { message = success }));
        }
Пример #14
0
 public ActionResult ModeDetails_PartialView(ModeModel model)
 {
     return(PartialView(model));
 }
Пример #15
0
 public JsonResult Edit(int?id)
 {
     return(Json(ModeModel.getModeById(id), JsonRequestBehavior.AllowGet));
 }
Пример #16
0
 public ActionResult GetGrid()
 {
     return(View(ModeModel.getAllMode()));
 }