Beispiel #1
0
        private void VacationEditor()
        {
            var vacationOfEmpoloyee = _employees[_mainView.dataGridViewUsers.CurrentRow.Index].Vacation;
            var view = new VacationView();

            view.SetObjectToEdit = vacationOfEmpoloyee;
            if (view.ShowDialog() == DialogResult.OK)
            {
                RefreshView();
            }
        }
        public IActionResult AddnewVacation(Guid personId, VacationView vacation)
        {
            Person person = Personrepository.IncludeGet(p => p.Team).FirstOrDefault(x => x.Id == personId);

            if (!VacationServices.CreateVacation(personId, vacation))
            {
                ModelState.AddModelError("EndDay", "Please change date");
                ViewBag.AddDays = person.Days;
                List <Weekend> weekends = Weekendrepository.Get(p => p.startDate > DateTime.Now).ToList();
                ViewBag.weekends = weekends;
                ViewBag.PersonId = personId;
                return(View(vacation));
            }
            return(Redirect("/Home/Workers/Home/Workers"));
        }
        public ActionResult AddVacation(VacationView vacation, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                vacation.EmployeeID = Convert.ToInt32(Session["UserID"]);
                if (file != null && !CheckContentType(file.ContentType))
                {
                    return(Json(new { success = false, message = "File format is not supported, please upload a PDF file!" }, JsonRequestBehavior.AllowGet));
                }
                else if (file != null && file.ContentLength > 0)
                {
                    try
                    {
                        string path = vacation.Attatchment;

                        path = Path.Combine(Server.MapPath("/Content/Files"),
                                            Path.GetFileName(file.FileName));
                        file.SaveAs(path);
                        vacation.Attatchment = path;

                        ViewBag.Message = "File uploaded successfully";
                    }
                    catch (Exception ex)
                    {
                        GlobalVariable.log.Error(ex);
                        // ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    }
                }
                //else
                //{
                //    ViewBag.Message = "You have not specified a file.";
                //}
                try
                {
                    HttpResponseMessage response = GlobalVariable.ApiClient.PostAsJsonAsync <VacationView>("vacations/PostVacation", vacation).Result;

                    if (response.IsSuccessStatusCode)
                    {
                        return(Json(new { success = true, message = "Added Successfully" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        var totalDays  = (vacation.EndDate - vacation.StartDate).TotalDays;
                        var totalHours = (vacation.EndDate - vacation.StartDate).TotalHours;
                        if (Math.Abs(totalDays) > 14 && vacation.Type == Types.Annual)
                        {
                            return(Json(new { success = false, message = "Only 14 days or less are allowed for Annual vacation!" }, JsonRequestBehavior.AllowGet));
                        }
                        else if (Math.Abs(totalHours) > 8 && vacation.Type == Types.Leave)
                        {
                            return(Json(new { success = false, message = "Only 8 hours or less are allowed for Leave Request!" }, JsonRequestBehavior.AllowGet));
                        }
                        return(Json(new { success = false, message = "You have exceeded the limit of annual vacation days" }, JsonRequestBehavior.AllowGet));

                        // return Json(new { success = false, message = "Only 14 days or less are allowed for Annual vacation!" }, JsonRequestBehavior.AllowGet);
                    }
                }
                catch (Exception ex) {
                    GlobalVariable.log.Error(ex.Message);
                    return(Json(new { success = false, message = "Oops! Something went wrong, please try again later" }, JsonRequestBehavior.AllowGet));
                }
            }
            return(View("AddNewVacation", vacation));
        }