public static void AddJunction(this tbl_junction junction, JunctionViewModel junctionVm)
 {
     junction.tenant_id     = junctionVm.tenant_id;
     junction.project_id    = junctionVm.project_id;
     junction.ps_id         = junctionVm.ps_id;
     junction.junction_name = junctionVm.junction_name;
     junction.created_date  = DateTime.Now;
     junction.created_by    = junctionVm.created_by;
     junction.modified_date = DateTime.Now;
     junction.modified_by   = junctionVm.modified_by;
 }
Exemple #2
0
        public HttpResponseMessage SaveJunction(HttpRequestMessage request, JunctionViewModel junction)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    tbl_junction newJunction = new tbl_junction();
                    newJunction.AddJunction(junction);
                    for (var i = 0; i < junction.junComponents.Count; i++)
                    {
                        var newJunComponent = new tbl_junctionComponents();
                        newJunComponent.tenant_id = junction.tenant_id;
                        newJunComponent.project_id = newJunction.project_id;
                        newJunComponent.junction_id = newJunction.id;
                        newJunComponent.component = junction.junComponents[i].component;
                        newJunComponent.quantity = junction.junComponents[i].quantity;
                        newJunction.junComponents.Add(newJunComponent);
                    }
                    _junctionRepository.Add(newJunction);
                    _unitOfWork.Commit();

                    for (var i = 0; i < junction.junComponents.Count; i++)
                    {
                        tbl_workprogress newworkprogress = new tbl_workprogress();
                        newworkprogress.tenant_id = junction.tenant_id;
                        newworkprogress.junction_id = newJunction.id;
                        newworkprogress.AddWorkprogress(junction);
                        newworkprogress.jun_component = junction.junComponents[i].component;
                        newworkprogress.total = junction.junComponents[i].quantity;
                        newworkprogress.completed = 0;
                        newworkprogress.pending = 0;
                        newworkprogress.progress = 0;
                        _workprogressRepository.Add(newworkprogress);

                        tbl_workverification newworkverification = new tbl_workverification();
                        newworkverification.tenant_id = junction.tenant_id;
                        newworkverification.project_id = junction.project_id;
                        newworkverification.ps_id = junction.ps_id;
                        newworkverification.junction_id = newJunction.id;
                        newworkverification.subcontractor_id = 0;
                        newworkverification.assigned_date = DateTime.Now;
                        newworkverification.jun_component = junction.junComponents[i].component;
                        newworkverification.total = junction.junComponents[i].quantity;
                        newworkverification.completed = 0;
                        newworkverification.verified_by = 0;
                        newworkverification.verification_status = 0;
                        newworkverification.verified_quantity = 0;
                        newworkverification.nc_quantity = 0;
                        newworkverification.created_date = DateTime.Now;
                        _workverificationRepository.Add(newworkverification);

                        _unitOfWork.Commit();
                    }
                    response = request.CreateResponse <JunctionViewModel>(HttpStatusCode.Created, junction);
                }
                return response;
            }));
        }