/// <summary>
 /// Get Customer Document Details By CustDocId
 /// </summary>
 /// <param name="custDocId">Int32:custDocId</param>
 /// <returns></returns>
 public CustomerDocumentsDTO GetCustomerDocumentDetailsByCustDocId(int custDocId)
 {
     CustomerDocumentsDTO customerDocuments = new CustomerDocumentsDTO();
     AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<customerdocument>>()
     .GetSingle(item => item.CustDoc_Doc_Id == custDocId && item.CustDoc_IsDeleted == false), customerDocuments);
     return customerDocuments;
 }
    private void SaveDocumentListForCustomer()
    {
        IList<CustomerDocDetailsDTO> listDocDetail = new List<CustomerDocDetailsDTO>();
        IList<CustomerDocumentsDTO> listCustDocument = new List<CustomerDocumentsDTO>();

        foreach (GridViewRow row in grdDocument.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                if (((TextBox)(row.Cells[3].Controls[1])).Text != string.Empty)
                {
                    CustomerDocDetailsDTO custDocDetails = new CustomerDocDetailsDTO();
                    custDocDetails.Cust_Doc_CustId = Convert.ToInt32(ViewState[Globals.StateMgmtVariables.CUSTOMERID]);
                    custDocDetails.Cust_Doc_DocId = Convert.ToInt32(grdDocument.DataKeys[row.RowIndex].Value);
                    custDocDetails.Cust_Doc_No = ((TextBox)(row.Cells[3].Controls[1])).Text;

                    DateTimeFormatInfo dateTimeFormatterProvider = DateTimeFormatInfo.CurrentInfo.Clone() as DateTimeFormatInfo;
                    dateTimeFormatterProvider.ShortDatePattern = "dd/MM/yyyy";
                    if (((TextBox)(row.Cells[4].Controls[1])).Text != string.Empty)
                    {
                        custDocDetails.Cust_Doc_ExDate = DateTime.Parse(((TextBox)(row.Cells[4].Controls[1])).Text, dateTimeFormatterProvider);
                    }

                    CustomerDocumentsDTO custDocument = new CustomerDocumentsDTO();
                    custDocument.CustDoc_CreatedBy = base.GetCurrentUserId();
                    custDocument.CustDoc_CreatedDate = DateTime.Now;

                    if (((Label)(row.Cells[6].Controls[1])).Text.Trim() != string.Empty)
                    {
                        string filePath = Path.Combine(Convert.ToString(ViewState[Globals.StateMgmtVariables.FILEPATH]),
                            ((Label)(row.Cells[6].Controls[1])).Text);
                        custDocument.CustDoc_File = ImageToBlob.ConvertImageToByteArray(filePath);
                    }
                    else
                    {
                        custDocument.CustDoc_File = null;
                    }

                    listCustDocument.Add(custDocument);

                    custDocDetails.Cust_Doc_FileName = ((Label)(row.Cells[6].Controls[1])).Text;
                    custDocDetails.Cust_Doc_CreatedBy = GetCurrentUserId();
                    custDocDetails.Cust_Doc_CreatedDate = DateTime.Now;
                    custDocDetails.Cust_Doc_LastUpdatedDate = DateTime.Now;

                    listDocDetail.Add(custDocDetails);
                }
            }
        }


        //Save Customer Document Details
        ESalesUnityContainer.Container.Resolve<ICustomerService>().SaveAndUpdateCustomerDocumentDetails(listDocDetail, listCustDocument);
        DeleteFiles();
    }
Exemplo n.º 3
0
        public void EditCustomerDocumentDetails(IList<CustomerDocDetailsDTO> listCustDocDetails, IList<CustomerDocumentsDTO> listCustDocument)
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {
                for (int i = 0; i < listCustDocDetails.Count; i++)
                {
                    customerdocdetail custDocdetailsEntity = new customerdocdetail();

                    CustomerDocService custDocuments = new CustomerDocService();
                    CustomerDocDetailsDTO customerDocDetail = custDocuments.GetCustomerDocumentDetailsByDocIdAndCustId(
                        listCustDocDetails[i].Cust_Doc_CustId, listCustDocDetails[i].Cust_Doc_DocId);

                    if (customerDocDetail.Cust_Doc_Id > 0)
                    {
                        AutoMapper.Mapper.Map(customerDocDetail, custDocdetailsEntity);

                        custDocdetailsEntity.Cust_Doc_FileName = listCustDocDetails[i].Cust_Doc_FileName;
                        custDocdetailsEntity.Cust_Doc_No = listCustDocDetails[i].Cust_Doc_No;
                        custDocdetailsEntity.Cust_Doc_ExDate = listCustDocDetails[i].Cust_Doc_ExDate;

                        ESalesUnityContainer.Container.Resolve<IGenericRepository<customerdocdetail>>()
                            .Update(custDocdetailsEntity);
                    }
                    else
                    {
                        AutoMapper.Mapper.Map(listCustDocDetails[i], custDocdetailsEntity);
                        ESalesUnityContainer.Container.Resolve<IGenericRepository<customerdocdetail>>()
                            .Save(custDocdetailsEntity);
                    }

                    CustomerDocumentsDTO customerDocument = new CustomerDocumentsDTO();
                    CustomerDocumentsViewDTO customerDocumentView = new CustomerDocumentsViewDTO();
                    AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<customerdocumentsview>>()
                    .GetSingle(item => item.CustDoc_Doc_Id == custDocdetailsEntity.Cust_Doc_Id && item.CustDoc_IsDeleted == false), customerDocumentView);

                    AutoMapper.Mapper.Map(customerDocumentView, customerDocument);

                    customerdocument custDocumentEntity = new customerdocument();

                    if (customerDocument.CustDoc_Id > 0)
                    {
                        AutoMapper.Mapper.Map(customerDocument, custDocumentEntity);

                        if (listCustDocument[i].CustDoc_File == null)
                        {
                            custDocumentEntity.CustDoc_IsDeleted = true;
                        }
                        else
                        {
                            custDocumentEntity.CustDoc_File = listCustDocument[i].CustDoc_File;
                        }

                        ESalesUnityContainer.Container.Resolve<IGenericRepository<customerdocument>>().Update(custDocumentEntity);
                    }
                    else
                    {
                        AutoMapper.Mapper.Map(listCustDocument[i], custDocumentEntity);
                        custDocumentEntity.CustDoc_Doc_Id = custDocdetailsEntity.Cust_Doc_Id;

                        ESalesUnityContainer.Container.Resolve<IGenericRepository<customerdocument>>().Save(custDocumentEntity);
                    }
                }
                transactionScope.Complete();
            }
        }
	/// <summary>
	/// 
	/// </summary>
	/// <returns></returns>
	private void SaveDocumentListForCustomer()
	{
		IList<CustomerDocDetailsDTO> listDocDetail = new List<CustomerDocDetailsDTO>();
		IList<CustomerDocumentsDTO> listCustDocument = new List<CustomerDocumentsDTO>();

		foreach (GridViewRow row in grdDocument.Rows)
		{
			if (row.RowType == DataControlRowType.DataRow)
			{
				if (((TextBox)(row.Cells[3].Controls[1])).Text != string.Empty)
				{
					CustomerDocDetailsDTO custDocDetails = new CustomerDocDetailsDTO();
					custDocDetails.Cust_Doc_CustId = Convert.ToInt32(ViewState[Globals.StateMgmtVariables.CUSTOMERID]);
					custDocDetails.Cust_Doc_DocId = Convert.ToInt32(grdDocument.DataKeys[row.RowIndex].Value);
					custDocDetails.Cust_Doc_No = ((TextBox)(row.Cells[3].Controls[1])).Text;

					DateTimeFormatInfo dateTimeFormatterProvider = DateTimeFormatInfo.CurrentInfo.Clone() as DateTimeFormatInfo;
					dateTimeFormatterProvider.ShortDatePattern = "dd/MM/yyyy";
					if (((TextBox)(row.Cells[4].Controls[1])).Text != string.Empty)
					{
						custDocDetails.Cust_Doc_ExDate = DateTime.Parse(((TextBox)(row.Cells[4].Controls[1])).Text, dateTimeFormatterProvider);
					}

					CustomerDocumentsDTO custDocument = new CustomerDocumentsDTO();
					custDocument.CustDoc_CreatedBy = base.GetCurrentUserId();
					custDocument.CustDoc_CreatedDate = DateTime.Now;

					//If fileupload control has file
					if (filAuthDoc.HasFile)
					{
						string uploadFilePath = Path.Combine(Server.MapPath("../CustomerAuthImages"), filAuthDoc.FileName);
						filAuthDoc.SaveAs(uploadFilePath);

						custDocument.CustDoc_File = ImageToBlob.ConvertImageToByteArray(uploadFilePath);
						custDocDetails.Cust_Doc_FileName = filAuthDoc.FileName;
						//Delete the file from application folder after converting into byte array
						File.Delete(uploadFilePath);
					}
					else
					{
						custDocument.CustDoc_File = null;
					}

					listCustDocument.Add(custDocument);

					custDocDetails.Cust_Doc_CreatedBy = GetCurrentUserId();
					custDocDetails.Cust_Doc_CreatedDate = DateTime.Now;
					custDocDetails.Cust_Doc_LastUpdatedDate = DateTime.Now;

					listDocDetail.Add(custDocDetails);
				}
			}
		}

		//Save Customer Document Details
		ESalesUnityContainer.Container.Resolve<ICustomerService>().EditCustomerDocumentDetails(listDocDetail, listCustDocument);
	}