public async Task <IHttpActionResult> SubmitTask(AddRequest param)
        {
            try
            {
                using (var context = new LeaveRequestDataContext())
                {
                    var usr   = context.Employees.Where(o => o.ID == param.ID).SingleOrDefault();
                    var token = usr.Token;

                    var bodyCreate = "{" +
                                     "\"data\": {" +
                                     "\"form_data\": {" +
                                     "\"pvAction\" : \"" + param.Action + "\"" +
                                     "}," +
                                     "\"comment\": \"ThisComent\"" +
                                     "}" +
                                     "}";

                    JObject jsonCreate = JObject.Parse(bodyCreate);
                    var     action     = string.Empty;

                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri("https://mosaic.dev.nextflow.tech/");
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        var response = await client.PostAsJsonAsync("nextflow/api/tasks/" + param.TaskId + "/submit", jsonCreate);

                        var result = await response.Content.ReadAsAsync <dynamic>();
                    }
                    if (param.Action == "Approve" || param.Action == "Disapprove")
                    {
                        var leaveReq = context.ListLeaveRequests.Where(o => o.ProcessId == param.ProcessId).SingleOrDefault();
                        leaveReq.status = param.Action;
                        context.SubmitChanges();

                        if (param.Action == "Approve")
                        {
                            var employ = context.Employees.Where(o => o.Email == leaveReq.Email).SingleOrDefault();
                            employ.Balance = (int)employ.Balance + (int)param.DaysLeave;
                            context.SubmitChanges();
                        }
                    }

                    commentHistory commentHistory = new commentHistory();

                    commentHistory.ProcessId = param.ProcessId;
                    commentHistory.Name      = usr.Name;
                    commentHistory.Action    = param.Action;
                    commentHistory.Date      = DateTime.Now;
                    commentHistory.Comment   = "jajajaj";

                    context.commentHistories.InsertOnSubmit(commentHistory);
                    context.SubmitChanges();


                    return(Ok(new { success = true, message = "Leave Request " + action }));
                }
            }
            catch (Exception ex)
            {
                return(Ok(new { success = false, message = ex.Message }));
            }
        }
Пример #2
0
        public async Task <IHttpActionResult> updateData([FromBody] AddRequest param)
        {
            try
            {
                using (var context = new PurchaserRequisitionDataContext())
                {
                    var usr   = context.Companies.Where(o => o.Email == param.Email).FirstOrDefault();
                    var token = usr.Token;

                    var bodyCreate = "{" +
                                     "\"data\": {" +
                                     "\"form_data\": {" +
                                     "\"pvAction\" : \"" + param.Action + "\"," +
                                     " \"pvApprover\": \"[email protected]\"," +
                                     " \"pvReq\": \"" + param.Email + "\"" +
                                     "}," +
                                     "\"comment\": \"Tes\"" +
                                     "}" +
                                     "}";

                    JObject jsonCreate = JObject.Parse(bodyCreate);
                    var     action     = string.Empty;

                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri("https://mosaic.dev.nextflow.tech/");
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        var response = await client.PostAsJsonAsync("nextflow/api/tasks/" + param.TaskId + "/submit", jsonCreate);

                        var result = await response.Content.ReadAsAsync <dynamic>();
                    }

                    if (param.Action == "Edit")
                    {
                        var requester = context.RequesterSummaries.Where(o => o.ProcessId == param.ProcessId).FirstOrDefault();
                        requester.ApproveStatus     = null;
                        requester.Name              = param.Name;
                        requester.Email             = param.Email;
                        requester.Payroll           = param.Payroll;
                        requester.RequesterPosition = param.RequesterPosition;
                        requester.AsalCompany       = param.AsalCompany;
                        requester.Location          = param.Location;
                        requester.Plant             = param.Plant;
                        requester.BudgetSource      = param.BudgetSource;
                        requester.Currency          = param.Currency;
                        requester.Date              = param.Date;
                        requester.SinglePanel       = param.SinglePanel;
                        requester.ItemText          = param.ItemText;
                        requester.MaterialGroup     = param.MaterialGroup;
                        requester.Description       = param.Description;
                        requester.Qty       = param.Qty;
                        requester.QtySatuan = param.QtySatuan;
                        requester.EstPrice  = param.EstPrice;
                        requester.Subtotal  = param.Qty * param.EstPrice;
                        context.SubmitChanges();

                        CommentHistory commentHistory = new CommentHistory();

                        commentHistory.ProcessId = param.ProcessId;
                        commentHistory.Name      = usr.Name;
                        commentHistory.Action    = param.Action;
                        commentHistory.Date      = DateTime.Now;
                        commentHistory.Comment   = "Sudah diedit";

                        context.CommentHistories.InsertOnSubmit(commentHistory);
                        context.SubmitChanges();
                    }
                    return(Ok(new { success = true, message = "Request " + action }));
                }
            }
            catch (Exception ex)
            {
                return(Ok(new { success = false, message = ex.Message }));
            }
        }
        public async Task <IHttpActionResult> Create([FromBody] AddRequest req)
        {
            var              flowId  = ConfigurationManager.AppSettings["FlowId"];
            commentHistory   comment = new commentHistory();
            ListLeaveRequest leave   = new ListLeaveRequest();

            using (var dc = new LeaveRequestDataContext())
            {
                var    user      = dc.Employees.Where(o => o.Email == req.Email).SingleOrDefault();
                string recordId  = string.Empty;
                string processId = string.Empty;

                var bodyCreate = "{ " +
                                 "\"data\": { " +
                                 " \"definition\": { " +
                                 " \"id\": \"" + flowId + "\"" +
                                 "}" +
                                 "}" +
                                 "}";

                JObject jsonCreate = JObject.Parse(bodyCreate);

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("https://mosaic.dev.nextflow.tech/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", user.Token);
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    var response = await client.PostAsJsonAsync("nextflow/api/records", jsonCreate);

                    var result = await response.Content.ReadAsAsync <dynamic>();

                    recordId = result.data.id;

                    var bodySubmit = "{ " +
                                     "\"data\": { " +
                                     " \"form_data\": { " +
                                     " \"pvInitiator\": \"" + user.Email + "\"," +
                                     " \"pvInitiatorName\": \"" + user.Name + "\"," +
                                     " \"pvAction\": \"Submit\"," +
                                     " \"pvReq\": \"" + user.Email + "\"," +
                                     " \"pvApprover\":\"[email protected]\"" +
                                     "}," +
                                     "\"comment\" : \"" + req.comment + "\"" +
                                     "}" +
                                     "}";

                    JObject jsonSubmit     = JObject.Parse(bodySubmit);
                    var     responseSubmit = await client.PostAsJsonAsync("nextflow/api/records/" + recordId + "/submit", jsonSubmit);

                    var resultSubmit = await responseSubmit.Content.ReadAsAsync <dynamic>();

                    processId = resultSubmit.data.process_id;
                }

                leave.Name       = req.Name;
                leave.Email      = req.Email;
                leave.DaysLeave  = req.DaysLeave;
                leave.ProcessId  = processId;
                leave.RecordId   = recordId;
                leave.StartDate  = req.StartDate;
                leave.EndDate    = req.EndDate;
                leave.DaysLeave  = req.DaysLeave;
                leave.Submission = DateTime.Now;
                leave.status     = req.status;
                leave.LeaveType  = req.LeaveType;


                dc.ListLeaveRequests.InsertOnSubmit(leave);


                comment.Name      = req.Name;
                comment.ProcessId = req.ProcessId;
                comment.Action    = "Submit";
                comment.Comment   = req.comment;
                dc.commentHistories.InsertOnSubmit(comment);

                dc.SubmitChanges();
            }
            return(Ok("Sukses"));
        }
Пример #4
0
        public async Task <IHttpActionResult> Create([FromBody] AddRequest req)
        {
            var              flowId    = ConfigurationManager.AppSettings["FlowId"];
            CommentHistory   comment   = new CommentHistory();
            RequesterSummary requester = new RequesterSummary();

            using (var dc = new PurchaserRequisitionDataContext())
            {
                var data = dc.Companies.FirstOrDefault(o => o.Name == req.Name);

                string RecordId  = string.Empty;
                string ProcessId = string.Empty;

                var bodyCreate = "{ " +
                                 "\"data\": { " +
                                 " \"definition\": { " +
                                 " \"id\": \"" + flowId + "\"" +
                                 "}" +
                                 "}" +
                                 "}";

                JObject jsonCreate = JObject.Parse(bodyCreate);

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("https://mosaic.dev.nextflow.tech/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", data.Token);
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    var response = await client.PostAsJsonAsync("nextflow/api/records", jsonCreate);

                    var result = await response.Content.ReadAsAsync <dynamic>();

                    RecordId = result.data.id;

                    var bodySubmit = "{ " +
                                     "\"data\": { " +
                                     " \"form_data\": { " +
                                     " \"pvInitiator\": \"" + data.Email + "\"," +
                                     " \"pvInitiatorName\": \"" + data.Name + "\"," +
                                     " \"pvAction\": \"submit\"," +
                                     " \"pvReq\": \"" + data.Email + "\"," +
                                     " \"pvApprover\": \"[email protected]\"" +
                                     "}," +
                                     "\"comment\" : \"" + req.comment + "\"" +
                                     "}" +
                                     "}";

                    JObject jsonSubmit     = JObject.Parse(bodySubmit);
                    var     responseSubmit = await client.PostAsJsonAsync("nextflow/api/records/" + RecordId + "/submit", jsonSubmit);

                    var resultSubmit = await responseSubmit.Content.ReadAsAsync <dynamic>();

                    ProcessId = resultSubmit.data.process_id;
                }

                requester.Name              = req.Name;
                requester.Email             = req.Email;
                requester.Payroll           = req.Payroll;
                requester.RequesterPosition = req.RequesterPosition;
                requester.AsalCompany       = req.AsalCompany;
                requester.Location          = req.Location;
                requester.Plant             = req.Plant;
                requester.BudgetSource      = req.BudgetSource;
                requester.Currency          = req.Currency;
                requester.Date              = req.Date;
                requester.SinglePanel       = req.SinglePanel;
                requester.ItemText          = req.ItemText;
                requester.MaterialGroup     = req.MaterialGroup;
                requester.Description       = req.Description;
                requester.Qty       = req.Qty;
                requester.QtySatuan = req.QtySatuan;
                requester.EstPrice  = req.EstPrice;
                requester.Subtotal  = req.Qty * req.EstPrice;
                requester.ProcessId = ProcessId;
                requester.RecordId  = RecordId;

                dc.RequesterSummaries.InsertOnSubmit(requester);
                dc.SubmitChanges();

                comment.Name      = req.Name;
                comment.ProcessId = ProcessId;
                comment.Action    = "Submit";
                comment.Date      = DateTime.Now;
                comment.Comment   = "Tolong diperiksa dengan saksama";
                dc.CommentHistories.InsertOnSubmit(comment);
                dc.SubmitChanges();
            }

            return(Ok("Success"));
        }