public ActionResult Duplicate(int id)
        {
            SlotRange range = SlotRangeModel.GetSlotRange(id);

            if (range == null)
            {
                return(View("NoSuchRange"));
            }
            int?rId = range.GetResponsible();

            if (IsAuthorized(range))
            {
                return(View(range));
            }
            else
            {
                SessionManager.RedirectAccessDenied(HttpContext.Request.RequestContext);
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// Checks the Encounter Slot for RNG calls before the Nature loop.
        /// </summary>
        /// <param name="slot">Slot Data</param>
        /// <param name="pkm">Ancillary pkm data for determining how to check level.</param>
        /// <returns>Slot number for this frame & lead value.</returns>
        public bool IsSlotCompatibile(EncounterSlot slot, PKM pkm)
        {
            bool usesLevel = !slot.FixedLevel;

            if (FrameType != FrameType.MethodH && (Lead & LeadRequired.UsesLevelCall) != 0 != usesLevel)
            {
                return(false);
            }

            // Level is before Nature, but usually isn't varied. Check ESV calc first.
            int s = GetSlot(slot);

            if (s != slot.SlotNumber)
            {
                return(false);
            }

            // Check Level Now
            int lvl = SlotRange.GetLevel(slot, Lead, RandLevel);

            if (pkm.HasOriginalMetLocation)
            {
                if (lvl != pkm.Met_Level)
                {
                    return(false);
                }
            }
            else
            {
                if (lvl > pkm.Met_Level)
                {
                    return(false);
                }
            }

            // Check if the slot is actually encounterable (considering Sweet Scent)
            bool encounterable = SlotRange.GetIsEncounterable(slot, FrameType, (int)(OriginSeed >> 16), Lead);

            return(encounterable);
        }
        // this method uses host-based authentication
        /// <summary>
        /// GET: /SlotRange/EmailScript/3
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult EmailScript(int id)
        {
            if (Request.Url.Host != "localhost" && Request.UserHostAddress != "127.0.0.1")
            {
                throw new Exception("access denied");
            }

            SlotRange range = SlotRangeModel.GetSlotRange(id);

            if (range == null)
            {
                throw new Exception("invalid id");
            }

            string script = range.GenerateScript();

            // get email address of resource manager
            List <Person> persons = PersonModel.GetResourceManagers();
            string        resMgrs = PersonModel.GetEmailCSV(persons);

            // send script to resourceManager(s) via E-Mail
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            //message.From = new System.Net.Mail.MailAddress("*****@*****.**");
            message.To.Add(resMgrs);
            message.IsBodyHtml   = false;
            message.Subject      = "Script Linux pour le SlotRange '" + range.id_slotRange + "'";
            message.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
            message.From         = new System.Net.Mail.MailAddress("*****@*****.**");
            message.Body         = script;

            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
            client.Send(message);

            // for demo backup, also write to a file


            return(View(range)); // can be implemented for testing purposes
        }
        public ActionResult Duplicate(int id, SlotRange target)
        {
            SlotRange source = SlotRangeModel.GetSlotRange(id);

            if (source == null)
            {
                return(View("NoSuchRange"));
            }
            int?rId = source.GetResponsible();

            if (IsAuthorized(source))
            {
                TimeSpan span = target.StartRes - source.StartRes;
                int      days = (int)span.TotalDays;
                SlotRangeModel.DuplicateSlotRange(source, days, source.IdCourse);
                return(RedirectToAction("CourseRanges", new { id = source.IdCourse }));
            }
            else
            {
                SessionManager.RedirectAccessDenied(HttpContext.Request.RequestContext);
                return(null);
            }
        }
Exemple #5
0
 /// <summary>
 /// Only use this for test methods.
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public int GetSlot(SlotType t) => SlotRange.GetSlot(t, RandESV, FrameType);
Exemple #6
0
        /// <summary>
        /// Gets all the slot ranges for the current course
        /// </summary>
        /// <returns>Return the slot ranges associated with the course</returns>
        public List <SlotRange> GetSlotRangesForCourse()
        {
            List <SlotRange> ranges = new List <SlotRange>();

            try
            {
                SqlConnection  db = new SqlConnection(connectionString);
                SqlTransaction transaction;

                db.Open();

                transaction = db.BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    SqlCommand cmd = new SqlCommand("SELECT [id_slotRange], [startRes] ,[endRes], [name] ,[id_course]" +
                                                    "FROM SlotRange SR " +
                                                    "WHERE id_course=@id " +
                                                    "ORDER BY SR.startRes ASC;", db, transaction);

                    cmd.Parameters.Add("@id", SqlDbType.Int).Value = this.ID;

                    SqlDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        DateTime startRes  = rdr.GetDateTime(rdr.GetOrdinal("startRes"));
                        DateTime endRes    = rdr.GetDateTime(rdr.GetOrdinal("endRes"));
                        string   name      = rdr.GetString(rdr.GetOrdinal("name"));
                        int      id_course = rdr.GetInt32(rdr.GetOrdinal("id_course"));

                        SlotRange range = new SlotRange(rdr.GetInt32(rdr.GetOrdinal("id_slotRange")), startRes, endRes, name, id_course);

                        ranges.Add(range);
                    }
                    rdr.Close();

                    foreach (var range in ranges)
                    {
                        //get slots
                        cmd = new SqlCommand("SELECT [id_slot], [start], [end] FROM Slot WHERE id_slotRange=@id;", db, transaction);
                        cmd.Parameters.Add("@id", SqlDbType.Int).Value = range.id_slotRange;
                        rdr = cmd.ExecuteReader();
                        //bool hasSetDuration = false;
                        int cpt = 0;
                        while (rdr.Read())
                        {
                            int      id_slot = rdr.GetInt32(rdr.GetOrdinal("id_slot"));
                            DateTime start   = rdr.GetDateTime(rdr.GetOrdinal("start"));
                            DateTime end     = rdr.GetDateTime(rdr.GetOrdinal("end"));

                            int startHour   = start.Hour;
                            int startMinute = start.Minute;

                            int endHour   = end.Hour;
                            int endMinute = end.Minute;
                            range.Startz.Add(startHour + ":" + startMinute);
                            range.Endz.Add(endHour + ":" + endMinute);
                            if (!range.Slotdate.Contains(start.Date))
                            {
                                range.Slotdate.Add(start.Date);
                            }
                            cpt++;

                            range.Slots.Add(new Slot(id_slot, start, end));
                        }
                        rdr.Close();
                        range.NumberOfSlots = cpt;

                        foreach (var slot in range.Slots)
                        {
                            //get reservations
                            cmd = new SqlCommand("SELECT [id_person], [id_slot], [numberMachines] FROM Reservation WHERE id_slot=@id;", db, transaction);
                            cmd.Parameters.Add("@id", SqlDbType.Int).Value = slot.ID;
                            rdr = cmd.ExecuteReader();

                            while (rdr.Read())
                            {
                                int id_person      = rdr.GetInt32(rdr.GetOrdinal("id_person"));
                                int id_slot        = rdr.GetInt32(rdr.GetOrdinal("id_slot"));
                                int numberMachines = rdr.GetInt32(rdr.GetOrdinal("numberMachines"));

                                slot.Reservations.Add(new Reservation(id_person, id_slot, numberMachines));
                            }
                            rdr.Close();
                        }
                    }
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new GrException(e, Messages.errProd);
                }
                finally
                {
                    db.Close();
                }
            }
            catch (Exception e)
            {
                if (e is GrException)
                {
                    throw e;
                }
                throw new GrException(e, Messages.errProd);
            }

            return(ranges);
        }
Exemple #7
0
 public int EncounterSlot(SlotType t) => SlotRange.GetSlot(t, ESV, FrameType);