public static void AddSubcontractor(this tbl_subcontractor subcontractor, SubContractorViewModel subcontractorVm)
 {
     subcontractor.tenant_id                  = subcontractorVm.tenant_id;
     subcontractor.company_name               = subcontractorVm.company_name;
     subcontractor.project_id                 = subcontractorVm.project_id;
     subcontractor.reg_No                     = subcontractorVm.reg_No;
     subcontractor.subcontractor_name         = subcontractorVm.subcontractor_name;
     subcontractor.current_street             = subcontractorVm.current_street;
     subcontractor.current_country            = subcontractorVm.current_country;
     subcontractor.current_state              = subcontractorVm.current_state;
     subcontractor.current_city               = subcontractorVm.current_city;
     subcontractor.current_zip                = subcontractorVm.current_zip;
     subcontractor.current_contact_number     = subcontractorVm.current_contact_number;
     subcontractor.alternative_contactNumber  = subcontractorVm.alternative_contactNumber;
     subcontractor.contractor_photo_file_name = subcontractorVm.contractor_photo_file_name;
     subcontractor.service_tax_no             = subcontractorVm.service_tax_no;
     subcontractor.pan                            = subcontractorVm.pan;
     subcontractor.bank_account_no                = subcontractorVm.bank_account_no;
     subcontractor.bank_name                      = subcontractorVm.bank_name;
     subcontractor.bank_branch                    = subcontractorVm.bank_branch;
     subcontractor.ifsc                           = subcontractorVm.ifsc;
     subcontractor.contractor_photo               = subcontractorVm.contractor_photo;
     subcontractor.contractor_photo_file_type     = subcontractorVm.contractor_photo_file_type;
     subcontractor.agreement                      = subcontractorVm.agreement;
     subcontractor.agreement_file_type            = subcontractorVm.agreement_file_type;
     subcontractor.contractor_agreement_file_name = subcontractorVm.contractor_agreement_file_name;
     subcontractor.created_date                   = DateTime.Now;
     subcontractor.created_by                     = subcontractorVm.created_by;
     subcontractor.modified_date                  = DateTime.Now;
     subcontractor.modified_by                    = subcontractorVm.modified_by;
 }
Exemplo n.º 2
0
        public HttpResponseMessage SaveSubContractor(HttpRequestMessage request, SubContractorViewModel subcontractor)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newSubContractor = new tbl_subcontractor()
                    {
                        tenant_id = subcontractor.tenant_id,
                        project_id = subcontractor.project_id,
                        company_name = subcontractor.company_name,
                        reg_No = subcontractor.reg_No,
                        subcontractor_name = subcontractor.subcontractor_name,
                        current_street = subcontractor.current_street,
                        current_country = subcontractor.current_country,
                        current_state = subcontractor.current_state,
                        current_city = subcontractor.current_city,
                        current_zip = subcontractor.current_zip,
                        current_contact_number = subcontractor.current_contact_number,
                        alternative_contactNumber = subcontractor.alternative_contactNumber,
                        contractor_photo_file_name = subcontractor.contractor_photo_file_name,
                        service_tax_no = subcontractor.service_tax_no,
                        pan = subcontractor.pan,
                        bank_account_no = subcontractor.bank_account_no,
                        bank_name = subcontractor.bank_name,
                        bank_branch = subcontractor.bank_branch,
                        ifsc = subcontractor.ifsc,
                        contractor_photo = subcontractor.contractor_photo,
                        contractor_photo_file_type = subcontractor.contractor_photo_file_type,
                        agreement = subcontractor.agreement,
                        agreement_file_type = subcontractor.agreement_file_type,
                        contractor_agreement_file_name = subcontractor.contractor_agreement_file_name,
                        created_date = DateTime.Now,
                        created_by = subcontractor.created_by,
                        modified_date = DateTime.Now,
                        modified_by = subcontractor.modified_by,
                        email_id = subcontractor.email_id
                    };



                    for (int i = 0; i < subcontractor.scomponentslist.Count; i++)
                    {
                        var newscComponents = new tbl_subcontractor_components();
                        newscComponents.tenant_id = subcontractor.tenant_id;
                        newscComponents.project_id = subcontractor.project_id;
                        newscComponents.subcontractor_id = newSubContractor.id;
                        newscComponents.subcontractor_name = subcontractor.subcontractor_name;
                        newscComponents.component_id = subcontractor.scomponentslist[i].component_id;
                        newscComponents.component_name = subcontractor.scomponentslist[i].component_name;

                        _subcontractorRepository.Add(newSubContractor);
                        _scComponentsRepository.Add(newscComponents);
                    }
                    _unitOfWork.Commit();
                    response = request.CreateResponse <SubContractorViewModel>(HttpStatusCode.Created, subcontractor);
                }
                return response;
            }));
        }
Exemplo n.º 3
0
        public HttpResponseMessage UpdateSubContractor(HttpRequestMessage request, SubContractorViewModel subcontractorviewmodel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var existingUser = _subcontractorRepository.GetSingle(subcontractorviewmodel.id);
                    existingUser.company_name = subcontractorviewmodel.company_name;
                    existingUser.project_id = subcontractorviewmodel.project_id;
                    existingUser.reg_No = subcontractorviewmodel.reg_No;
                    existingUser.subcontractor_name = subcontractorviewmodel.subcontractor_name;
                    existingUser.current_street = subcontractorviewmodel.current_street;
                    existingUser.current_country = subcontractorviewmodel.current_country;
                    existingUser.current_state = subcontractorviewmodel.current_state;
                    existingUser.current_city = subcontractorviewmodel.current_city;
                    existingUser.current_zip = subcontractorviewmodel.current_zip;
                    existingUser.current_contact_number = subcontractorviewmodel.current_contact_number;
                    existingUser.alternative_contactNumber = subcontractorviewmodel.alternative_contactNumber;

                    existingUser.service_tax_no = subcontractorviewmodel.service_tax_no;
                    existingUser.pan = subcontractorviewmodel.pan;
                    existingUser.bank_account_no = subcontractorviewmodel.bank_account_no;
                    existingUser.bank_name = subcontractorviewmodel.bank_name;
                    existingUser.bank_branch = subcontractorviewmodel.bank_branch;
                    existingUser.ifsc = subcontractorviewmodel.ifsc;

                    existingUser.contractor_photo = subcontractorviewmodel.contractor_photo;
                    existingUser.contractor_photo_file_type = subcontractorviewmodel.contractor_photo_file_type;
                    existingUser.contractor_photo_file_name = subcontractorviewmodel.contractor_photo_file_name;

                    existingUser.contractor_agreement_file_name = subcontractorviewmodel.contractor_agreement_file_name;
                    existingUser.agreement = subcontractorviewmodel.agreement;
                    existingUser.agreement_file_type = subcontractorviewmodel.agreement_file_type;

                    existingUser.modified_date = DateTime.Now;
                    existingUser.modified_by = subcontractorviewmodel.modified_by;
                    existingUser.email_id = subcontractorviewmodel.email_id;
                    _subcontractorRepository.Edit(existingUser);

                    //deleting existing comps..
                    var existingSc_id_sc_comps = _scComponentsRepository.GetAll().Where(s => s.subcontractor_id == subcontractorviewmodel.id);
                    foreach (var sc_comp in existingSc_id_sc_comps)
                    {
                        _scComponentsRepository.Delete(sc_comp);
                    }

                    //adding new comps..
                    for (int i = 0; i < subcontractorviewmodel.scomponentslist.Count; i++)
                    {
                        var newscComponents = new tbl_subcontractor_components();
                        newscComponents.tenant_id = subcontractorviewmodel.tenant_id;
                        newscComponents.project_id = subcontractorviewmodel.project_id;
                        newscComponents.subcontractor_id = subcontractorviewmodel.id;
                        newscComponents.subcontractor_name = subcontractorviewmodel.subcontractor_name;
                        newscComponents.component_id = subcontractorviewmodel.scomponentslist[i].component_id;
                        newscComponents.component_name = subcontractorviewmodel.scomponentslist[i].component_name;

                        _scComponentsRepository.Add(newscComponents);
                    }

                    _unitOfWork.Commit();
                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                return response;
            }));
        }
Exemplo n.º 4
0
 public SubContractor()
 {
     InitializeComponent();
     _SCVM            = new SubContractorViewModel();
     this.DataContext = _SCVM;
 }
Exemplo n.º 5
0
        public JsonResult _AddSubContractorF(SubContractorViewModel subcontractorviewmodel)
        {
            if (ModelState.IsValid)
            {
                // Set Record Info
                string   UserNameInit = @User.Identity.Name.ToString();
                DateTime CreatedInit  = DateTime.Now;

                var userid = (from x in db.AspNetUsers
                              where x.UserName == UserNameInit
                              select x).FirstOrDefault();



                if (subcontractorviewmodel.SubContractorID != null)
                {
                    // Update SubContractor


                    SubContractor subcontractor = db.SubContractors.Single(x => x.SubContractorID == subcontractorviewmodel.SubContractorID);
                    subcontractor.SubContractorName = subcontractorviewmodel.SubContractorName;
                    subcontractor.Active            = subcontractorviewmodel.Active;
                    subcontractor.Address           = subcontractorviewmodel.Address;
                    subcontractor.CityBinID         = subcontractorviewmodel.CityBinID;
                    subcontractor.StateBinID        = subcontractorviewmodel.StateBinID;
                    subcontractor.ZipCode           = subcontractorviewmodel.ZipCode;
                    subcontractor.CountyBinID       = subcontractorviewmodel.CountyBinID;
                    subcontractor.DateUpdated       = CreatedInit;
                    subcontractor.UpdatedBy         = UserNameInit;
                    db.SaveChanges();


                    return(Json(new { Status = "Success", Modified = subcontractorviewmodel.SubContractorID }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    // Create SubContractor

                    SubContractor sc = new SubContractor
                    {
                        SubContractorName = subcontractorviewmodel.SubContractorName,
                        Active            = subcontractorviewmodel.Active,
                        Address           = subcontractorviewmodel.Address,
                        CityBinID         = subcontractorviewmodel.CityBinID,
                        StateBinID        = subcontractorviewmodel.StateBinID,
                        ZipCode           = subcontractorviewmodel.ZipCode,
                        CountyBinID       = subcontractorviewmodel.CountyBinID,
                        DateUpdated       = CreatedInit,
                        UpdatedBy         = UserNameInit
                    };


                    try
                    {
                        db.SubContractors.Add(sc);
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Debug.WriteLine("Property: {0} Error: {1}",
                                                validationError.PropertyName, validationError.ErrorMessage);
                            }
                        }
                    }

                    // SubContractor ID
                    var SCID = sc.SubContractorID;


                    if (subcontractorviewmodel.CancerTypeName != null)
                    {
                        // Cancer Types

                        var stringToSplitA = subcontractorviewmodel.CancerTypeName;

                        var queryA = from valA in stringToSplitA.Split(',')
                                     select Convert.ToInt32(valA);

                        foreach (int valA in queryA)
                        {
                            // Add to AgencyContactClinics

                            SubContractorClinics subcontractorclinics = new SubContractorClinics
                            {
                                SubContractorID = SCID,
                                SiteID          = subcontractorviewmodel.SiteID,
                                ClinicID        = Convert.ToInt32(subcontractorviewmodel.SiteID),
                                ProgramID       = Convert.ToInt32(subcontractorviewmodel.ProgramID),
                                CancerTypeBinID = valA,
                                IsClinic        = false
                            };

                            db.SubContractorClinics.Add(subcontractorclinics);
                            db.SaveChanges();
                        }
                    }



                    return(Json(new { Status = "Success", Modified = subcontractorviewmodel.SubContractorID }, JsonRequestBehavior.AllowGet));
                }
            }


            return(Json(new { Status = "Success" }, JsonRequestBehavior.AllowGet));
        }