Esempio n. 1
0
        public HttpStatusCode CreateOvertimeForm(OvertimeFormViewModels overtimeFormViewModels)
        {
            var           httpClient    = new HttpClient();
            StringContent stringContent = new StringContent(JsonConvert.SerializeObject(overtimeFormViewModels), Encoding.UTF8, "application/json");
            var           result        = httpClient.PostAsync("https://localhost:44346/api/OvertimeForm/Apply/", stringContent).Result;

            return(result.StatusCode);
        }
Esempio n. 2
0
        public ActionResult SubmitRejectManager(OvertimeFormViewModels overtimeFormViewModels)
        {
            var data = overtimeFormEmployeeRepository.RejectRM(overtimeFormViewModels);

            if (data == 1)
            {
                return(Ok(new { status = "Reject success" }));
            }
            else
            {
                return(StatusCode(500, new { status = "Internal Server Error" }));
            }
        }
Esempio n. 3
0
        public ActionResult SubmitApprovedRM(OvertimeFormViewModels overtimeFormVM)
        {
            var data = overtimeFormEmployeeRepository.ApprovedRM(overtimeFormVM);

            if (data == 1)
            {
                return(Ok(new { status = "Approved success" }));
            }
            else
            {
                return(StatusCode(500, new { status = "Internal Server Error" }));
            }
        }
Esempio n. 4
0
        public ActionResult SubmitRejectSupervisor(OvertimeFormViewModels overtimeFormVM)
        {
            var data = overtimeFormEmployeeRepository.RejectSupervisor(overtimeFormVM);

            if (data == 1)
            {
                return(Ok(new { status = "Request Reject" }));
            }
            else
            {
                return(StatusCode(500, new { status = "Internal Server Error" }));
            }
        }
Esempio n. 5
0
 public IActionResult AddOvertime(OvertimeFormViewModels overtimeFormViewModels)
 {
     if (ModelState.IsValid)
     {
         var data = overtimeFormRepository.Apply(overtimeFormViewModels);
         if (data > 0)
         {
             return(Ok(new { status = "Request Added" }));
         }
         else
         {
             return(StatusCode(500, new { status = "Internal server error" }));
         }
     }
     else
     {
         return(BadRequest(new { status = "Bad request", errorMessage = "Data input is not valid" }));
     }
 }
        public int RejectRM(OvertimeFormViewModels overtimeFormVM)
        {
            var data = myContext.OvertimeFormEmployee.Where(e => e.Id == overtimeFormVM.Id).FirstOrDefault();

            if (data == null)
            {
                return(0);
            }
            if (data.Status == StatusRequest.Waiting)
            {
                return(0);
            }
            if (data.Status == StatusRequest.ApproveByRelatonalManager)
            {
                return(0);
            }

            if (data.Status == StatusRequest.ApproveBySupervisor)
            {
                data.Status = StatusRequest.Reject;
                myContext.Update(data);
                RequestViewModels result3 = null;

                string connectStr = Configuration.GetConnectionString("MyConnection");

                using (IDbConnection db = new SqlConnection(connectStr))
                {
                    string readSp    = "sp_get_email_employee";
                    var    parameter = new { NIK = overtimeFormVM.NIK, CustomerId = overtimeFormVM.CustomerId };
                    result3 = db.Query <RequestViewModels>(readSp, parameter, commandType: CommandType.StoredProcedure).FirstOrDefault();
                }
                sendEmail.SendRejectNotificationToEmployee(result3.Email);
            }
            else
            {
                return(0);
            }
            myContext.SaveChanges();
            return(1);
        }
Esempio n. 7
0
        public int Apply(OvertimeFormViewModels overtimeFormViewModels)
        {
            var correction = myContext.Employee.Where(a => a.NIK == overtimeFormViewModels.NIK).FirstOrDefault();

            if (correction.CustomerId == overtimeFormViewModels.CustomerId)
            {
                var overtimeForm = new OvertimeForm()
                {
                    Name           = overtimeFormViewModels.Name,
                    CustomerId     = overtimeFormViewModels.CustomerId,
                    SubmissionDate = overtimeFormViewModels.SubmissionDate
                };
                myContext.Add(overtimeForm);
                var resultOvertimeForm = myContext.SaveChanges();
                for (int i = 0; i < overtimeFormViewModels.listdetails.Count; i++)
                {
                    var listdata = new DetailOvertimeRequest();
                    listdata.StartTime        = overtimeFormViewModels.listdetails[i].StartTime;
                    listdata.EndTime          = overtimeFormViewModels.listdetails[i].EndTime;
                    listdata.Act              = overtimeFormViewModels.listdetails[i].Act;
                    listdata.AdditionalSalary = overtimeFormViewModels.listdetails[i].AdditionalSalary;
                    listdata.OvertimeFormId   = overtimeForm.Id;

                    myContext.Add(listdata);
                }
                ;
                var resultDetails = myContext.SaveChanges();

                var condition = myContext.OvertimeForm.Where(a => a.Name == overtimeFormViewModels.Name).FirstOrDefault();

                if (condition != null)
                {
                    OvertimeFormViewModels result = null;

                    string connectStr = Configuration.GetConnectionString("MyConnection");

                    using (IDbConnection db = new SqlConnection(connectStr))
                    {
                        string readSp    = "sp_get_info";
                        var    parameter = new { Name = overtimeFormViewModels.Name };
                        result = db.Query <OvertimeFormViewModels>(readSp, parameter, commandType: CommandType.StoredProcedure).FirstOrDefault();
                    }

                    OvertimeFormViewModels result2 = null;

                    using (IDbConnection db = new SqlConnection(connectStr))
                    {
                        string readSp    = "sp_get_id";
                        var    parameter = new { Id = condition.Id + (result.Amount - 1) };
                        result2 = db.Query <OvertimeFormViewModels>(readSp, parameter, commandType: CommandType.StoredProcedure).FirstOrDefault();
                    }

                    var addRequest = new OvertimeFormEmployee()
                    {
                        NIK            = overtimeFormViewModels.NIK,
                        CustomerId     = overtimeFormViewModels.CustomerId,
                        OvertimeFormId = result2.Id,
                        Status         = StatusRequest.Waiting
                    };

                    myContext.Add(addRequest);
                }
                var resultRequest = myContext.SaveChanges();

                if (resultOvertimeForm > 0 && resultDetails > 0 && resultRequest > 0)
                {
                    OvertimeFormViewModels result = null;

                    string connectStr        = Configuration.GetConnectionString("MyConnection");
                    var    employeeCondition = myContext.Employee.Where(a => a.NIK == overtimeFormViewModels.NIK).FirstOrDefault();

                    if (employeeCondition != null)
                    {
                        using (IDbConnection db = new SqlConnection(connectStr))
                        {
                            string readSp    = "sp_get_email_employee";
                            var    parameter = new { NIK = overtimeFormViewModels.NIK, CustomerId = overtimeFormViewModels.CustomerId };
                            result = db.Query <OvertimeFormViewModels>(readSp, parameter, commandType: CommandType.StoredProcedure).FirstOrDefault();
                        }
                    }
                    sendEmail.SendNotificationToEmployee(result.Email);

                    OvertimeFormViewModels result2 = null;
                    using (IDbConnection db = new SqlConnection(connectStr))
                    {
                        string readSp    = "sp_get_email_supervisor";
                        var    parameter = new { CustomerId = result.CustomerId, RoleId = 3 };
                        result2 = db.Query <OvertimeFormViewModels>(readSp, parameter, commandType: CommandType.StoredProcedure).FirstOrDefault();
                    }
                    sendEmail.SendNotificationToSupervisor(result2.Email);
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return(0);
            }
        }