예제 #1
0
        public async Task <JsonResult> Create(FormCollection fc)
        {
            Overtimerate o = OvertimerateHelper.GetObject(null, fc);

            Dictionary <string, object> err = null;

            ISession se = NHibernateHelper.CurrentSession;

            err = o.IsValid(se);

            if (err == null)
            {
                await Task.Run(() =>
                {
                    using (ITransaction tx = se.BeginTransaction())
                    {
                        se.SaveOrUpdate(o);
                        tx.Commit();
                    }
                });

                return(Json(new Dictionary <string, object>
                {
                    { "success", 1 },
                    { "message", "Overtime Rate  was successfully added." }
                },
                            JsonRequestBehavior.AllowGet));
            }

            else
            {
                return(Json(err, JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        public async Task <ActionResult> Edit(int id)
        {
            ViewBag.form_id = "edit-form";

            ISession     se = NHibernateHelper.CurrentSession;
            Overtimerate o  = await Task.Run(() => { return(se.Get <Overtimerate>(id)); });

            return(View("_form", o));
        }
예제 #3
0
        private static async Task CreateOvertimeRate(ISession se)
        {
            Random r = new Random();

            await Task.Run(() =>
            {
                for (int y = 2000; y <= DateTime.Now.Year; y++)
                {
                    Overtimerate o = new Overtimerate {
                        Duration = 1, Year = y, Payrate = r.Next(10, 50)
                    };
                    se.SaveOrUpdate(o);
                }
            });
        }
예제 #4
0
        public static async Task <double> GetTotalOvertimeEarnings(Dictionary <string, object> filters, double duration)
        {
            int year = (int)filters["year"];

            ISession se = NHibernateHelper.CurrentSession;

            Overtimerate o = await Task.Run(() =>
            {
                return(se.QueryOver <Overtimerate>()
                       .Where(x => x.Year == year).Skip(0).Take(1).SingleOrDefault());
            });

            double total = 0;

            if (o != null)
            {
                total = (duration / o.Duration) * o.Payrate;
            }

            return(total);
        }
예제 #5
0
        public static Overtimerate GetObject(Overtimerate o, FormCollection fc)
        {
            string paramDuration = fc.Get("duration");
            double duration      = CommonHelper.GetValue <double>(paramDuration);

            string paramYear = fc.Get("year");
            int    year      = CommonHelper.GetValue <int>(paramYear);

            string paramPayRate = fc.Get("pay_rate");
            double payRate      = CommonHelper.GetValue <double>(paramPayRate);

            if (o == null)
            {
                o = new Overtimerate();
            }

            o.Duration = duration;
            o.Year     = year;
            o.Payrate  = payRate;

            return(o);
        }