Example #1
0
 public IHttpActionResult updateData([FromBody] RequesterSummary req)
 {
     try
     {
         if (req != null)
         {
             using (var dc = new PurchaserRequisitionDataContext())
             {
                 var data = dc.RequesterSummaries.FirstOrDefault(o => o.Id == req.Id);
                 {
                     data.Manager = req.Manager;
                 };
                 dc.SubmitChanges();
                 return(Ok(data));
             }
         }
         else
         {
             return(Unauthorized());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Example #2
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"));
        }