Example #1
0
        public PartialViewResult GetDay(int year = 0, int month = 0, int day = 0)
        {
            var UserId = User.Identity.Name;

            year  = (year == 0) ? DateTime.Now.Year : year;
            month = (month == 0) ? DateTime.Now.Month : month;
            day   = (day == 0) ? DateTime.Now.Day : day;

            var hYear = new HoursOfYear(UserId, year);
            var model = hYear.Hours.FirstOrDefault(x => x.Date.Month == month && x.Date.Day == day);

            // Aggiungo le liste WorkType e Ordini
            if (model.WorkTypeRegular == WorkType.NonGiustificato || ((int)model.WorkTypeRegular >= (int)WorkType.PermessoNonRetribuito && (int)model.WorkTypeRegular <= (int)WorkType.Viaggio))
            {
                ViewBag.lstWorkType = DAL.SelectList.WorkTypesNotJustified(model.Travel > TimeSpan.Zero, hYear.ExtraAmount >= model.LessTime);
            }

            ViewBag.lstUserOrders = DAL.SelectList.UserOrders(UserId);
            // Titolo del Popup
            ViewBag.PopupTitle = "Modifica Giorno";
            ViewBag.Title      = GetTitle(model.Date);
            return(PartialView("_ManageDay", model));
        }
Example #2
0
        public PartialViewResult CreateEditWorkOrder(Models.Orders.WorkOrder model)
        {
            // Aggiungo gli ordini dell'utente
            ViewBag.lstUserOrders = DAL.SelectList.UserOrders(model.UserId);

            if (!ModelState.IsValid)
            {
                Response.StatusCode = 500;
                return(PartialView("_ManageWorkOrder", model));
            }
            try
            {
                // Verifico che non siano troppe le ore inserite
                var hYear         = new HoursOfYear(model.UserId, model.Date.Year);
                var hDay          = hYear.Hours.FirstOrDefault(x => x.Date.Month == model.Date.Month && x.Date.Day == model.Date.Day);
                var avaiableHours = hDay.WorkTime + hDay.Travel - hDay.OrdersTimeComplete;
                if (model.Hours > avaiableHours)
                {
                    throw new Exception("Ore impostate maggiori delle ore disponibili");
                }

                // verifico se l'utente e teamleader
                model.UserApprove = (db.Orders.Any(x => x.OrderId == model.OrderId && x.TeamLeaderId == model.UserId)) ? model.UserId : null;

                // aggiungo il costo orario e verifico se il tipo e dirigente
                var user = hYear.User;
                if (user.HoursProfile.CostDaily)
                {
                    // Sabato
                    if (model.Date.DayOfWeek == DayOfWeek.Saturday)
                    {
                        model.Cost = 0;
                    }
                    // Festivo e Domenica
                    else if (hDay.Ordinary == TimeSpan.Zero && (hDay.WorkTime + hDay.Travel) < new TimeSpan(8, 0, 0))
                    {
                        model.Cost = (user.Cost / new TimeSpan(8, 0, 0).TotalHours) * model.Hours.TotalHours;
                    }
                    // In settimana minore dell'ordinario
                    else if ((hDay.WorkTime + hDay.Travel) < hDay.Ordinary)
                    {
                        model.Cost = (user.Cost / hDay.Ordinary.TotalHours) * model.Hours.TotalHours;
                    }
                    else
                    {
                        model.Cost = (user.Cost / hDay.WorkTime.TotalHours) * model.Hours.TotalHours;
                    }
                }
                else
                {
                    model.Cost = model.Hours.TotalHours * user.Cost;
                }
                // Aggiungo o modifico del db
                db.WorkOrders.AddOrUpdate(m => new { m.UserId, m.OrderId, m.Date }, model);
                db.SaveChanges();
                ViewBag.Success = "La modifica รจ stata eseguita";
                return(GetDay(model.Date.Year, model.Date.Month, model.Date.Day));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.MySqlExMessage());
                Response.StatusCode = 500;
                return(PartialView("_ManageWorkOrder", model));
            }
        }