public IActionResult ApproveByScrumMaster(int id)
        {
            var username = this.GetCurrentUserName();

            var repo = this.Storage.GetRepository <IRequestOvertimeRepository>();

            RequestOvertime requestOvertime = repo.WithKey(id);

            if (requestOvertime == null)
            {
                return(this.NotFound(new { success = false }));
            }

            if (requestOvertime.HasFeedbackByScrumMaster() || requestOvertime.HasFeedbackByHumanResource())
            {
                this.ModelState.AddModelError("id", "Already have feedback by Scrum Master or HR");
            }

            if (this.ModelState.IsValid)
            {
                // TODO : find correct Employee ID from Username
                requestOvertime.ScrumMasterApproved(10, GetCurrentUserName());

                this.Storage.Save();

                return(Ok(new { success = true }));
            }
            else
            {
                return(BadRequest());
            }
        }
        public ActionResult Create(RequestOvertimeCreateViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                RequestOvertime requestOvertime = model.ToEntity();
                this.Storage.GetRepository <IRequestOvertimeRepository>().Create(requestOvertime, this.GetCurrentUserName());
                this.Storage.Save();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public IActionResult Get(int id)
        {
            var repo = this.Storage.GetRepository <IRequestOvertimeRepository>();

            RequestOvertime requestOvertime = repo.WithKey(id);

            if (requestOvertime == null)
            {
                return(this.NotFound(new { success = false }));
            }

            return(Ok(new { success = true, data = requestOvertime }));
        }
        public IActionResult ApproveByHumanResourceDept(int id)
        {
            var username = this.GetCurrentUserName();

            var repo = this.Storage.GetRepository <IRequestOvertimeRepository>();

            RequestOvertime requestOvertime = repo.WithKey(id);

            if (requestOvertime == null)
            {
                return(this.NotFound(new { success = false }));
            }

            return(Ok(new { success = true }));
        }
        public IActionResult RejectByHumanResourceDept([FromRoute] int id)
        {
            var             username        = this.GetCurrentUserName();
            var             repo            = this.Storage.GetRepository <IRequestOvertimeRepository>();
            RequestOvertime requestOvertime = repo.WithKey(id);

            if (requestOvertime == null)
            {
                return(this.NotFound(new { success = false }));
            }
            requestOvertime.HumanResourceDeptRejected(20, GetCurrentUserName());

            this.Storage.Save();
            return(Ok(new { success = true }));
        }
        public IActionResult Delete(int id)
        {
            var repo = this.Storage.GetRepository <IRequestOvertimeRepository>();

            RequestOvertime requestOvertime = repo.WithKey(id);

            if (requestOvertime == null)
            {
                return(this.NotFound(new { success = false }));
            }

            repo.Delete(requestOvertime, GetCurrentUserName());
            this.Storage.Save();

            return(Ok(new { success = true }));
        }
        public IActionResult ApproveByScrumMaster(int id)
        {
            var username = this.GetCurrentUserName();

            var repo = this.Storage.GetRepository <IRequestOvertimeRepository>();

            RequestOvertime requestOvertime = repo.WithKey(id);

            if (requestOvertime == null)
            {
                return(this.NotFound(new { success = false }));
            }

            // TODO : find correct Employee ID from Username
            // quickLeave.ScrumMasterApproved(0);

            return(Ok(new { success = true }));
        }
        public async Task <IActionResult> PostAsync(RequestOvertimeCreateViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                RequestOvertime requestOvertime = model.ToEntity();
                var             repo            = this.Storage.GetRepository <IRequestOvertimeRepository>();

                //var imageUrl = await _imageService.UploadImageAsync(model.Image);
                //requestOvertime.ImageUrl = imageUrl.ToString();

                repo.Create(requestOvertime, GetCurrentUserName());
                this.Storage.Save();

                return(Ok(new { success = true }));
            }

            return(BadRequest(new { success = false }));
        }
        public IActionResult Put(int id, RequestOvertimeUpdateViewModel model)
        {
            var repo = this.Storage.GetRepository <IRequestOvertimeRepository>();

            RequestOvertime requestOvertime = repo.WithKey(id);

            if (requestOvertime == null)
            {
                return(this.NotFound(new { success = false }));
            }

            if (this.ModelState.IsValid)
            {
                model.ToEntity(requestOvertime, this.GetCurrentUserName());
                repo.Edit(requestOvertime, GetCurrentUserName());
                this.Storage.Save();

                return(Ok(new { success = true }));
            }

            return(BadRequest(new { success = false }));
        }
        public IActionResult RejectByHumanResourceDept([FromRoute] int id)
        {
            var             username        = this.GetCurrentUserName();
            var             repo            = this.Storage.GetRepository <IRequestOvertimeRepository>();
            RequestOvertime requestOvertime = repo.WithKey(id);

            if (requestOvertime == null)
            {
                return(this.NotFound(new { success = false }));
            }
            if (requestOvertime.HasFeedbackByScrumMaster() || requestOvertime.HasFeedbackByHumanResource())
            {
                this.ModelState.AddModelError("id", "Already have feedback by Srum Master or HR");
            }

            if (ModelState.IsValid)
            {
                requestOvertime.HumanResourceDeptRejected(20, GetCurrentUserName());

                this.Storage.Save();
                return(Ok(new { success = true }));
            }
            return(BadRequest());
        }