Esempio n. 1
0
        public int AddToDogHistory(UpgradeDogView upgradeDogView)
        {
            String sql;
            int Id = upgradeDogView.Id;
            if (Id > 0)
            {
                sql = @"Update DogHistory
                        Set dogid = @DogId, comments = @Comments, WinDate=@WinDate, ShowName=@ShowName, ClassWon=@ClassWon, NewGrade=@NewGrade, UpgradeType=@UpgradeType, DateOfWin=@DateOfWin
                        WHERE DogHistoryId = @Id";
            }
            else
            {
                sql = @"INSERT INTO DogHistory (dogid, comments, WinDate, ShowName, ClassWon, NewGrade, UpgradeType, DateOfWin)
                    VALUES( @DogId, @Comments, @WinDate, @ShowName, @ClassWon, @NewGrade, @UpgradeType, @DateOfWin)";

            }
            var windate = new MySqlParameter("@WinDate", MySqlDbType.DateTime);
            windate.Value = upgradeDogView.WinDate;
            Id = RunProcedure(sql, new MySqlParameter[] {
                new MySqlParameter("@Id", upgradeDogView.Id),
                new MySqlParameter("@DogId", upgradeDogView.DogId),
                new MySqlParameter("@Comments", upgradeDogView.Comments),
                windate,
                new MySqlParameter("@ShowName", upgradeDogView.ShowName),
                new MySqlParameter("@ClassWon", upgradeDogView.ClassWon),
                new MySqlParameter("@NewGrade", upgradeDogView.NewGrade),
                new MySqlParameter("@UpgradeType", upgradeDogView.UpgradeType),
                new MySqlParameter("@DateOfWin", upgradeDogView.DateOfWin)
                });

            return Id;
        }
        public static StatusCls UpgradeDog(UpgradeDogView upgradeDogView)
        {
            var status = new StatusCls();
            AppException.LogEvent($"Upgrade Dog (UserID={upgradeDogView.UserId}, DogId={upgradeDogView.DogId})");
            try
            {
                DateTime activeDate;
                var currentUser = new User(upgradeDogView.UserId);
                var dog = new Dogs(upgradeDogView.DogId);
                DogHistory.Add(upgradeDogView);
                var mm = new MailMessage();
                var oldgrade = dog.Grade;
                if (upgradeDogView.UpgradeType == 0)
                {

                    mm.Subject = "First Place Processing - Confirmation of grade change";
                    var body = "This is a confirmation of grade change of your dog: " + dog.KCName + " from grade " + oldgrade + " to grade " + upgradeDogView.NewGrade +
                                  Environment.NewLine + Environment.NewLine +
                                  "Your dog will be grade " + upgradeDogView.NewGrade + " from the " + upgradeDogView.WinDate.AddDays(25).ToString("dd MMM yyyy") +
                                  Environment.NewLine + Environment.NewLine;
                    mm.Body = body;
                    activeDate = upgradeDogView.WinDate.Add(new TimeSpan(25, 0, 0, 0));
                }
                else
                {
                    mm.Subject = "First Place Processing - Confirmation of grade change";
                    var body = "This is a confirmation of grade change of your dog: " + dog.KCName + " from grade " + oldgrade + " to grade " + upgradeDogView.NewGrade + Environment.NewLine + Environment.NewLine;
                    mm.Body = body;
                    activeDate = DateTime.Now;
                }
                EmailManager.Send(currentUser, mm);
                if (activeDate > DateTime.Now)
                {
                    status.Extra = activeDate.ToString("dd MMM yyyy");
                }
            }
            catch (Exception e)
            {
                AppException.LogEvent($"Error:UpgradeDog:{e.Message} {e.StackTrace}");
            }
            return status;
        }
        public JsonResult UpgradeDog(UpgradeDogView upgradeDog)
        {
            try { TrackUser("UpgradeDog", Newtonsoft.Json.JsonConvert.SerializeObject(upgradeDog)); } catch (Exception e )  { AppException.LogError(
                $"Error:UpgradeDog {upgradeDog.DogId} {e.Message} {CurrentUser?.UserID ?? -1}"); }

            if (upgradeDog.FromUser)
            {
                upgradeDog.UserId = CurrentUser.ID;
            }
            var dog = new Dogs(upgradeDog.DogId);
            var status = ProcessDog.ProcessDog.UpgradeDog(upgradeDog);
            var effectiveDate = DateTime.Now;
            var showsForUser = Shows.GetShowsForUser(upgradeDog.UserId);

            // get all shows entered but not closed
            var enteredShow = showsForUser
                                .Where(x => x.ClosingDate > DateTime.Now).ToList();

            // get all shows closed and entered and upgrade by win.
            var closedShows = new List<Shows>();
            var missedShows = new List<Shows>();
            if (upgradeDog.UpgradeType == 0)
            {
                var today = DateTime.Now;
                effectiveDate = upgradeDog.WinDate.AddDays(+25);
                closedShows = showsForUser
                            .Where(x => x.ClosingDate <= today && today < x.ShowDate.AddDays(-14) && effectiveDate <= x.ShowDate).ToList();

                var showIds = (from show in enteredShow let dogClasses = DogClasses.Retrieve(upgradeDog.DogId, show.ShowID) where !dogClasses.Any() select show).ToList();
                if (showIds.Any())
                {
                    foreach (var show in showIds)
                        enteredShow.Remove(show);
                }

                showIds = (from show in closedShows let dogClasses = DogClasses.Retrieve(upgradeDog.DogId, show.ShowID) where !dogClasses.Any() select show).ToList();
                if (showIds.Any())
                {
                    foreach (var show in showIds)
                        closedShows.Remove(show);
                }

                missedShows = showsForUser
                            .Where(x => x.ClosingDate <= today && today >= x.ShowDate.AddDays(-14) && effectiveDate < x.ShowDate).ToList();
                var tmp = closedShows.Aggregate("closedShows:", (current, item) => current + $"[{item.ShowName},{item.ShowDate.ToShortDateString()}],");

                tmp += "    missedShows:";
                tmp = missedShows.Aggregate(tmp, (current, item) => current + $"[{item.ShowName},{item.ShowDate.ToShortDateString()}],");
                AppException.LogEvent($"Upgrade Dog (effectiveDate={effectiveDate},{tmp})");
            }

            AppException.LogEvent(string.Format("Upgrade Dog UserId:{3}, DogId:{4} (enteredShow={0}, closedShows={1}, missedshows={2})",
                    enteredShow?.Count ?? -1,
                    (closedShows.Count),
                    (missedShows.Count),
                    upgradeDog.UserId,
                    upgradeDog.DogId));

            return Json(new
            {
                Status = 0,
                upgradeDog.DogId,
                upgradeDog.NewGrade,
                OldGrade = dog.Grade,
                upgradeDog.UpgradeType,
                EffectiveDate = effectiveDate.ToString("dd MMM yyyy"),
                DateActive = effectiveDate.ToString("yyyy-MM-dd hh:mm:ss"),
                enteredShow,
                closedShows,
                missedShows
            });
        }
Esempio n. 4
0
        public static void AddChampWins(UpgradeDogView upgradeDogView)
        {
            String moduleSettings = ModuleConfig.GetSettings();
            Fpp.Data.Dogs dogData = new Fpp.Data.Dogs(moduleSettings);
            int dogHistoryID;
            dogHistoryID = dogData.AddToDogHistory(upgradeDogView);

            DateTime activeDate = upgradeDogView.WinDate.Add(new TimeSpan(25, 0, 0, 0));
        }
Esempio n. 5
0
        public static int Add(UpgradeDogView upgradeDogView)
        {
            String moduleSettings = ModuleConfig.GetSettings();
            Fpp.Data.Dogs dogData = new Fpp.Data.Dogs(moduleSettings);
            int dogHistoryID;
            dogHistoryID = dogData.AddToDogHistory(upgradeDogView);

            DateTime activeDate = DateTime.Now;
            if (upgradeDogView.UpgradeType < 10)
            {
                activeDate = upgradeDogView.WinDate.Add(new TimeSpan(25, 0, 0, 0));
                if (upgradeDogView.UpgradeType == 1)
                {
                    activeDate = DateTime.Now;
                }
            }
            dogData.AddToDogGrades(upgradeDogView.DogId, activeDate, upgradeDogView.NewGrade, upgradeDogView.UpgradeType);

            return dogHistoryID;
        }
        public JsonResult Grade6Wins(List<Grade6WinsModel> grade6Wins)
        {
            var dogWins = DogHistory.GetRecordedWins(grade6Wins[0].DogId);
            foreach (var win in grade6Wins)
            {
                var tmp = new UpgradeDogView
                {
                    UpgradeType = 10,
                    ClassWon = win.ClassWon,
                    DateOfWin = win.DateOfWin,
                    ShowName = win.ShowName,
                    Id = win.Id,
                    DogId = win.DogId,
                    NewGrade = 6
                };
                var prevWin = dogWins.FirstOrDefault(d => d.Id == win.Id);
                if (prevWin != null)
                {
                    tmp.UpgradeType = prevWin.UpgradeType;
                    tmp.Comments = prevWin.Comments;
                }

                DogHistory.AddChampWins(tmp);
            }

            return Json(new
            {
                Status = 0
            });
        }